Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SequenceEqual in C# List

Posted on 2016-09-21
2
Medium Priority
?
211 Views
Last Modified: 2016-09-21
Hi,

I have 2 List<string>: list_A and list_B.
it has 3 items inside each.

I got the values from api call and they are:
Iist_A[0] : "Hello"
list_A[1]: "I am <br><br> Isabell"
list_A[2]: "Sincerely, <br><br>Isabell"

I retrieved the values from DB and stored those to list_B.
I added and deleted items on list_B since I had to manipulate the data and string.
So when I finally added items, the previously stored items were overwritten by the new ones.
However, at the end, this is what I got for list_B.
Iist_B[0] : "Hello"
list_B[1]: "I am <br><br> Isabell"
list_B[2]: "Sincerely, <br><br>Isabell"

When I checked the values using Locals window in Visual Studio, I verified that all the values were matched. I even used 'Text Visualizer', but the results were exactly matched.
However I am getting "false" on the following statement.

list_A.SequenceEqual(list_B);

Open in new window


How could this happen and how to fix this issue?
0
Comment
Question by:Isabell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 1000 total points
ID: 41809908
it should be equals and returned true if you compare to 2 same Lists

try check the 1st and 2nd results below
List<string> list_A = new List<string> { "Hello", "I am <br><br> Isabell", "Sincerely, <br><br>Isabell" };
            List<string> list_B = new List<string> { "Hello", "I am <br><br> Isabell", "Sincerely, <br><br>Isabell" };

            Boolean b = list_A.SequenceEqual(list_B);
            Response.Write("B = " + b.ToString() + "<br>");

            list_B.Add("test");
            b = list_A.SequenceEqual(list_B);
            Response.Write("B = " + b.ToString() + "<br>");

Open in new window

0
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1000 total points
ID: 41809946
I have copied your values to my code (below) - and it shows that lists are identical...:

            List<string> list_A = new List<string>();
            list_A.Add("Hello");
            list_A.Add("I am <br><br> Isabell");
            list_A.Add("Sincerely, <br><br>Isabell");
            List<string> list_B = new List<string>();
            list_B.Add("Hello");
            list_B.Add("I am <br><br> Isabell");
            list_B.Add("Sincerely, <br><br>Isabell");

            MessageBox.Show((list_A.SequenceEqual(list_B)).ToString());

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question