Created
April 24, 2014 03:14
-
-
Save shengoo/11240246 to your computer and use it in GitHub Desktop.
C# merge two list
This file contains 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; | |
class Program | |
{ | |
static void Main() | |
{ | |
List<int> a = new List<int>(); | |
a.Add(1); | |
a.Add(2); | |
a.Add(5); | |
a.Add(6); | |
// Contains: | |
// 1 | |
// 2 | |
// 5 | |
// 6 | |
int[] b = new int[3]; | |
b[0] = 7; | |
b[1] = 6; | |
b[2] = 7; | |
a.AddRange(b); | |
// Contains: | |
// 1 | |
// 2 | |
// 5 | |
// 6 | |
// 7 [added] | |
// 6 [added] | |
// 7 [added] | |
foreach (int i in a) | |
{ | |
Console.WriteLine(i); | |
} | |
} | |
} | |
=== Output of the program === | |
1 | |
2 | |
5 | |
6 | |
7 | |
6 | |
7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment