Skip to content

Instantly share code, notes, and snippets.

@nishanc
Last active December 12, 2021 13:42
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 nishanc/494b459ff8206d31e0494f56b083edcd to your computer and use it in GitHub Desktop.
Save nishanc/494b459ff8206d31e0494f56b083edcd to your computer and use it in GitHub Desktop.
string[] array = { "a", "b", "c", "d", "e" };
// Using Span ctor (array, start, length)
// Note that the spans overlap
var firstView = new Span<string>(array, 0, 3);
// firstView = { "a", "b", "c" }
var secondView = new Span<string>(array, 2, 3);
// secondView = { "c", "d", "e" }
firstView[0] = "w";
// array = { "w", "b", "c", "d", "e" }
firstView[2] = "x";
// array = { "w", "b", "x", "d", "e" }
secondView[0] = "y";
// array = { "w", "b", "y", "d", "e" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment