combine two lists c 23

Solutions on MaxInterview for combine two lists c 23 by the best coders in the world

showing results for - "combine two lists c 23"
Aarón
06 May 2018
1List<string> a = new List<string>();
2List<string> b = new List<string>();
3
4a.AddRange(b);
Theo
24 Jun 2018
1// Create your object
2public class A { int Id { get; set; } A() { } A(int id) { Id = id;} }
3public class B { int Id { get; set; } B() { } B(int id) { Id = id;} }
4
5// Construct your lists
6List<A> list = new List<A>() { new A( Id = 1 ), new A( Id = 2 ) };
7List<B> list1 = new List<B>() { new B( Id = 3 ), new B( Id = 4 ) };
8
9// Then create a linq query and convert the result to a list
10List<object> all = (from x in list select (object)x).ToList();
11
12// Now add the second list to the end of the last one
13all.AddRange((from x in list1 select (object)x).ToList());
14
15// You can use this new list to loop it like this
16foreach (object item in all)
17{
18	// If you want to check which object we are looping you do this:
19	bool obj1 = item is A;
20	// Now you can cast the item to your object in a conditional operator
21	Console.WriteLine(obj1 ? (item as A).Id : (item as B).Id);
22
23	// Output:
24	// 1
25	// 2
26  	// 3
27  	// 4
28}
Laura
02 Mar 2017
1class Program
2
3    {
4        static void Main(string[] args)
5        {
6            ArrayList CountryList1 = new ArrayList();
7            ArrayList CountryList2 = new ArrayList();
8
9            CountryList1.Add("Pakistan");
10            CountryList1.Add("Nepal");
11            CountryList2.Add("Butan");
12            CountryList2.Add("Srilanka");
13          
14            CountryList1.AddRange(CountryList2);
15        }
16
17    }
Gaelan
19 Apr 2019
1// Create your object
2public class A { int Id { get; set; } A() { } A(int id) { Id = id;} }
3public class B { int Id { get; set; } B() { } B(int id) { Id = id;} }
4
5// Construct your lists
6List<A> list = new List<A>() { new A( Id = 1 ), new A( Id = 2 ) };
7List<B> list1 = new List<B>() { new B( Id = 3 ), new B( Id = 4 ) };
8
9// Then create a linq query and convert the result to a list
10List<object> all = (from x in list select (object)x).ToList();
11
12// Now add the second list to the end of the last one
13all.AddRange((from x in list1 select (object)x).ToList());
14
15// You can use this new list to loop it like this
16foreach (object item in all)
17{
18	// If you want to check which object we are looping you do this:
19	bool obj1 = item is A;
20	// Now you can cast the item to your object in a conditional operator
21	Console.WriteLine(obj1 ? (item as A).Id : (item as B).Id);
22
23	// Output:
24	// 1
25	// 2
26  	// 3
27  	// 4
28}
29
queries leading to this page
merge 3 list c 23c 23 merge two arraylistcombine two class in list c 23c 23 merge lists comare on propertycombining two lists into a single list c 23c 23 inner join two listsunity add two lists in onec 23 join 2 list with comparec 23 combine different list objects together single list merge list c 23concat three lists c 23c 23 combine 2 lists with method syntaxc 23 combine two lists into onec 23 how to merge listsmerge two list in c 23c 23 merge array of listsc 23 combine two lists deduplicationcombine two liste c 23concat two lists in c 23best way to merge 2 lists in c 23 with conditioncombine two list of strings c 23join lists together c 23c 23 merge multiple listsadd to two different list c 23c 23 2 lists to a list of arraysc 23 how to merge 2 listsc 23 concat 2 listhow to merge two list on c 23how to add list1 to list2 c 23combine list in c 23c 23 combine two list togetherc 23 combine listshow to concat 2 list 3cint 3e c 23c 23 combine arraysc 23 combine two list with different propertiesconcate two list in c 23c 23 join listsmerge tow list c 23 from differenett typesput 2 lists together c 23how to add lists together c 23c 23 join two lists togetherc 23 concat list of listsc 23 merge two lists with id compareconcat two list c 23how to append two lists in c 23c 23 merge two listsc 23 joining two lists by a fieldc 23 create list from multiple listscombine multiple lists of objects into single list c 23c 23 merge liststwo list string string c 23combine list c 23combile two list of differene different types c 23 5cmerge two lists together c 23how to merge two lists cmerge lists c 23c 23 merge any list togetherc 23 add lists togetherjoin 2 lists c 23join two lists together c 23c 23 combine two lists item together based on common valuesadd two list together c 23add two lists in c 23how to merge two list boject in c 23c 23 join multiple listsc 23 combine two listc 23 add 2 listscombine two lists elements with some character in c 23c 23 combine two lists into new listc 23 merge two lists by idhow to join two lists in c 23c 23 combine two listsjoin two lists c 23c 23 combine array into stringmerge arraylist c 23how to merge two list string in c 23how to append two list in c 23how to merge two list in c 23 samplesc 23 join two listsc 23 concat lists from multiple objectshow to concat two list in c 23c 23 combine 2 listshow to add lists together in c 23merge two string lists c 23combine 2 lists c 23combine two lists c 23list to two lists c 23c 23 append two lists togetherhow to create method to merge lists c 23c 23 list combinec 23 join two different type listscombine multiple lists c 23how to concat 2 list in c 23c 23 join two lists with commaconcat two string lists c 23c 23 merge listc 23 merge two lists of different objectsc 23 list combine two listshow to merge two list in c 23combine 2 list in c 23how to add 2 list c 23c 23 combine two lists where items are the samec 23 add two listsc 23 concat listsc 23 list merge 2 listshow to combine lists in c 23combine two arraylist c 23c 23 merge list create objectjoin two different type of lists c 23c 23 add concat two listhow to merge two list in new single list in c 23how to add two list objects in c 23c 23 merge two lists nullc 23 merge lists of stringjoin multiple lists c 23join two lists objects c 23merge two lists c 23join 2 list c 23add two list into one c 23c 23 combine two lists by idc 23 merge and sort two listshow to add two lists together c 23c 23 combine two lists into tuplehow to merge two lists in c 23plus two array list in c 23combine values from list c 23how to concat 2 lists in c 23concat list c 23combine two list c 23c 23 how to merge data in a list that are the samec 23 efficient way to merge 2 listmerge two sorted lists c 23c 23 combine 2 lists into onemerge two lists with key c 23c 23 merge two lists of objectsc 23 list mergeconcat lists c 23adding 2 list c 23c 23 add 2 list togethermerge two different list c 23concat two lists c 23how to combine two list 3ct 3e c 23combine 2 lists into 1 c 23c 23 add two lists togetherc 23 join two lists on propertyhow to add two lists c 23c 23 concat 2 listshow to add two list in c 23c 23 combine two lists to onehow to combine two lists into one c 23 mvcc 23 join lists join 28 29 not workinghow to merge two arrays c 23how to merge two list c 23combine 2 list string in c 23combine cstrings from list c 23combine multiple lists in c 23append two lists together c 23putting two list together c 23c 23 combine two lists into a new listc 23 join two lists into tuple listcombine two string lists into one c 23join two different list c 23c 23 join multiple lists togetherc 23 how to join two listsc 23 combine 2 listc 23 concat lists of different typesadd two lists c 23c 23 how to merge two listsc 23 new list from two listscombine 2 arraylist c 23c 23 combine two lists of different typesmerge 2 lists with difference classes c 23c sharp combine two lists string intc 23 combine two tolistmerge array c 23concat multiple list c 23c 23 combine two lists only incommon itemscombine two list in c 23how to combine two lists into one c 23c 23 combine lists of different typesc 23 create new list from two listscombine 2 list with merge data in c 23c 23 merge list itemscombine lists of lists c 23add two lists together c 23join several lists c 23merge list items c 23merge tow list c 23c 23 combine list of listscombine two lists c 23 with different typeshow to add two lists in c 23merge two integer list in c 23how to join two lists c 23how to combine two lists in c 23merge 2 list in c 23c 23 how to merge two same listsc 23 how to combine two listsc 23 merge two lists based on propertyconcatenate two list c 23c 23 add multiple lists togetherc 23 merge two lists different typeslist merge c 23concate two list one by one in c 23join lists same type c 23merge two list c 23c 23 concat two listc 23 list join two listsc 23 combine two lists of same typehow to merge lists c 23how to combine 2 lists c 23add variables from two lists to one object c 23c 23 join two lists of objectsc 23 join 2 listsc 23 merge 2 listsc 23 declare multiple listsconcat 2 lists c 23merge list c 23c 23 combine two different listshow to create a new list with 2 different list c 23merge 2 list c 23c 23 merge list of objectsmerge objects in two lists c 23c 23 join of to listsc 23 list merge elementscombine two lists in c 23c 23 connect to listshow to combine 2 list in c 23combine lists c 23c 23 make list from 2 listshow to merge list in c 23c 23 combine listc 23 concat multiple listshow to merge two object lists in c 23c 23 create list from two listshow to combine two list in c 23join in two list with condition in c 23join lists c 23add 2 lists c 23concat two list in c 23c 23 concat 2 lists in placehow to combine arrays in c 23c 23 concat lists fro 2c multiple objectscombine 3 lists c 23merge two lists in c 23merge two different lists c 23best way to merge 2 lists in c 23combine two list items c 23combine two lists together c 23merge 2 lists c 23how to join 2 lists c 23c 23 join two lists on idconcat 2 list c 23how to add two list in one list in c 23c 23 merge two lists by propertyconcatenate 2 list c 23c 23 how to combine 2 listsc 23 combine two lists of objectscombine to lists c 23c 23 merge list of arraysc 23 add two list togetherc 23 merge three listscombine list values c 23combine several list together c 23union two lists c 23 linqhow to merge two lists c 23c 23 ling merge two listscombine two lists c 23