Skip to content

Instantly share code, notes, and snippets.

@mwolicki
Last active December 16, 2016 12:01
Show Gist options
  • Save mwolicki/9463f4fcd9c8dc61b4f861de3dc3a731 to your computer and use it in GitHub Desktop.
Save mwolicki/9463f4fcd9c8dc61b4f861de3dc3a731 to your computer and use it in GitHub Desktop.
class MainClass {
static void Main() {
System.Console.WriteLine("abcdef");
Mutate("abcdef");
System.Console.WriteLine("abcdef");
}
unsafe static void Mutate(string text) {
var newLen = text.Length * 2;
fixed (char* t = text) {
int* len = (int*)t;
len--;
*len = newLen;
for (int i = 0; i < newLen; i++)
t[i] = 'y';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment