The problem is:
Given two sorted lists, L1 and L2, then how i write a procedure to compute L1 n L2 (intersection) ?
can anyone help me , please?
hopefree
0
Newbie Poster
Recommended Answers
Jump to PostWith the help of LINQ this is easy:
static void Main(string[] args) { string[] first = { "John", "Dave", "Mary" }; string[] second = { "Danny", "Nicole", "Mary" , "James"}; IEnumerable<string> intersect = first.Intersect(second); Console.WriteLine("*** First array:"); foreach (string name in first) Console.WriteLine(name); Console.WriteLine("*** Second array:"); foreach …
Jump to PostOk, sortedList, what is the Key are Value type? Even the Linq query can deffer a lot, depending on the types.
Is it somethink like: SortedList<string, string> or do you use any custom objects inside?Mitja
Jump to PostI did an exampe with sortedList:
private Method() { Win32.AllocConsole(); SortedList<string, string> sList1 = PopulateList1(); SortedList<string, string> sList2 = PopulateList2(); //get only values which are equal in both sortedLists: var difList = sList1.Intersect(sList2).Select(a => a.Value).ToList(); foreach (var item in difList) Console.WriteLine(item); Console.ReadLine(); } private SortedList<string, string> PopulateList1() …
All 9 Replies
ddanbe
2,724
Professional Procrastinator
Featured Poster
Mitja Bonca
commented:
Linq is the best option :)
+2
Mitja Bonca
557
Nearly a Posting Maven
ddanbe
commented:
Could not give rep to your next post so I do it here.
+9
Mitja Bonca
557
Nearly a Posting Maven
hopefree
0
Newbie Poster
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Mitja Bonca
557
Nearly a Posting Maven
Mitja Bonca
557
Nearly a Posting Maven
hopefree
0
Newbie Poster
Mitja Bonca
557
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.