这导致AccessViolationException抛出:
using System;
namespace TestApplication
{
internal static class Program
{
private static unsafe void Main()
{
ulong* addr = (ulong*)Int64.MaxValue;
ulong val = *addr;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这会导致NullReferenceException抛出:
using System;
namespace TestApplication
{
internal static class Program
{
private static unsafe void Main()
{
ulong* addr = (ulong*)0x000000000000FF;
ulong val = *addr;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它们都是无效指针,都违反了内存访问规则.为什么NullReferenceException?