Solved

SequenceEqual in C# List

Posted on 2016-09-21
2
46 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 49

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now