Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created September 11, 2019 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/0a9f003386d9740473cad01a9ed0e785 to your computer and use it in GitHub Desktop.
Save guitarrapc/0a9f003386d9740473cad01a9ed0e785 to your computer and use it in GitHub Desktop.
array size change in C#
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