unsafe
keyword in a .Net project, you must check "Allow unsafe code" in Project Properties => Buildunsafe
).For instance, when you use a for loop an array like so:
for (int i = 0; i < array.Length; i++)
{
array[i] = 0;
}
.NET Framework ensures that you do not exceed the bounds of the array, throwing an IndexOutOfRangeException
if the index exceeds the bounds.
However, if you use unsafe code, you may exceed the array's bounds like so:
unsafe
{
fixed (int* ptr = array)
{
for (int i = 0; i <= array.Length; i++)
{
*(ptr+i) = 0;
}
}
}