NullReferenceException is a C# version of NullPointerException. To handle and catch it in C#, use try-catch.
The below example shows that a variable is set to null and when we try to print it, it throws an exception that gets caught in the catch −
Try { a = null; Console.WriteLine(a); }catch (NullPointerException ex) { Console.WriteLine("Variable is Null!"); }
上述代码将允许捕获异常并使用catch处理它。
위 내용은 C# 中的空指针异常의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!