Solved

SequenceEqual in C# List

Posted on 2016-09-21
2
108 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
2 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 250 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 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 250 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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