卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章64334本站已运行4115

C# 中的空指针异常

C# 中的空指针异常

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程序使用rename()函数更改文件名
下一篇: 一个C/C++指针谜题?
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏