Tutorial by Examples

void Main() { unsafe { int[] a = {1, 2, 3}; fixed(int* b = a) { Console.WriteLine(b[4]); } } } Running this code creates an array of length 3, but then tries to get the 5th item (index 4). On my machine, this printed 1910457872, bu...
When accessing arrays with pointers, there are no bounds check and therefore no IndexOutOfRangeException will be thrown. This makes the code faster. Assigning values to an array with a pointer: class Program { static void Main(string[] args) { unsafe { int...
var s = "Hello"; // The string referenced by variable 's' is normally immutable, but // since it is memory, we could change it if we can access it in an // unsafe way. unsafe // allows writing to memory; methods on Syste...

Page 1 of 1