Created
June 1, 2015 18:36
-
-
Save csdear/ae36bd8da71e88b458c0 to your computer and use it in GitHub Desktop.
List Concat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment