Created
September 11, 2019 01:59
-
-
Save guitarrapc/0a9f003386d9740473cad01a9ed0e785 to your computer and use it in GitHub Desktop.
array size change in C#
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
void Main() | |
{ | |
// resize | |
var a = new[] { 1, 2, 3 }; | |
Array.Resize(ref a, a.Length + 1); // 突然のref | |
a[a.Length - 1] = 4; | |
a.Dump(); | |
// copy | |
var b = new[] { 1, 2, 3 }; | |
var c = new int[4]; // 型明示が必要.... | |
Array.Copy(b, c, b.Length); | |
c[b.Length] = 4; | |
c.Dump(); | |
// concat | |
var d = new[] { 1, 2, 3 }; | |
var e = d.Concat(new[] {4}).ToArray(); // LINQ.... | |
e.Dump(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment