Null pointer exception in C#

PHPz
Release: 2023-09-21 23:57:04
forward
1391 people have browsed it

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!");
}
Copy after login

The above code will allow to catch the exception and handle it using catch.

The above is the detailed content of Null pointer exception in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!