C# 中的空指標異常

PHPz
發布: 2023-09-21 23:57:04
轉載
1392 人瀏覽過

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# 中的空指標異常的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!