Solved

SequenceEqual in C# List

Posted on 2016-09-21
2
147 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 52

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 30

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Universal App 22 63
asp.net repeater server posting 5 39
Health check of winows and webservces 5 52
vb.net make textbox not visible after 1 minute elapsed 6 27
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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