stuart-d2
6/1/2015 - 6:36 PM

List Concat

List Concat

//using System;
//using System.Collections.Generic;
//using System.Linq


//Concats two lists together, robot arms and robot legs into one list, 'resultlist'

class Program {

static void Main()
{
//list 1 Robot Arms
List<string> robotArms = new List<string>();
robotArms.Add("buzzsaw"); 
robotArms.Add("manipulator"); 
robotArms.Add("claw"); 

//list 2 Robot Legs - adding values a little differently.  
List<string> robotLegs = new List<string>() { "ball", "track", "wheels"};  

/*Now concatentate
Create a worker variable and call the the concat method on one list,
passing in the SECOND list as a parameter
*/
var result = robotArms.Concat(robotLegs);
/*Now create a worker' list. This is another interesting way to create a list
by calling the worker variable and the ToList() method.
If you ever have a list(s) in a local var/worker variable, you can make it a 
list proper with the ToList(); method.  
*/
List<string> resultList = result.ToList();

//Now lets see each entry 
foreach(var entry in resultList)
{
	Console.WriteLine(entry);
}
	
}

}
/*OUTPUT :
buzzsaw
manipulator
claw
ball
track
wheels
*/