Nullable is a term in C# that allows an extra value null to be owned by a form. We will learn in this article how to work with Nullable types in C#.
There are majorly two types of data types in C# Value and Reference type. We can not assign a null value directly to the Value data type, therefore, C# 2.0 provides us the Nullable types to assign a value data type to null.
What is Nullable types? the Nullable types used to assign the null value to the value data type. That means we can directly assign a null value to a value data type attribute. Using Nullable, we can declare a null value where T is a type like int, float, bool, etc.
Nullable types represent the Null value along with the actual range of that data type. Like the int data type can hold the value from -2147483648 to 2147483647 but a Nullable int can hold the value null and range from -2147483648 to 2147483647
How to declare Nullable types There are two ways to declare Nullable types.
Properties of Nullable types Nullable types have two properties.
Nullable a = null; Console.WriteLine(a.HasValue); // Print False Nullable b = 9; Console.WriteLine(b.HasValue); // Print True
Value: The value of the variable Nullable form is given by this property. If the variable has any value, the value will be returned; else, it will give the runtime InvalidOperationException exception when the variable value is null.
Nullable a = null;
Console.WriteLine(a.Value); // Gives run time exception of type 'InvalidOperationException'
Nullable b = 9;
Console.WriteLine(b.Value); // Print 9
You can read more about method of Nullable types and rules of using Nullable types in this blog here:
Guide to Python Programming Language
This article will explore how to generate QR code in Python and some useful creation features from pyqrcode library. QR codes recently became more popular than ever before, yet few people know that the first iterations of QR codes were created back in 1990s in Japan for the automotive industry.
Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?
Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.
Python Programming Tutorials For Beginners