
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are nullable data types in C#?
C# provides the nullable types, to which you can assign normal range of values as well as null values.
For example, you can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable variable. Similarly, you can assign true, false, or null in a Nullable variable.
The following is the syntax −
< data_type> ? <variable_name> = null;
Here is an example −
int? num1 = null;
Let us see the complete example to work with Nullable data types −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int? num1 = null; int? num2 = 45; double? num3 = new double?(); double? num4 = 3.14157; bool? boolval = new bool?(); // display the values Console.WriteLine("Nullables at Show: {0}, {1}, {2}, {3}", num1, num2, num3, num4); Console.WriteLine("A Nullable boolean value: {0}", boolval); Console.ReadLine(); } } }
Output
Nullables at Show: , 45, , 3.14157 A Nullable boolean value:
- Related Articles
- What are enumerated data types in C++?
- What are pointer data types in C#?
- What are dynamic data types in C#?
- What are object data types in C#?
- What are reference data types in C#?
- What are the data types, value types and reference types in C#?
- What are fundamental data types in C++ programming?
- What are user defined data types in C#?
- What are primary data types in C language?
- C# Nullable Datetime
- What are string and String data types in C#?
- What are different types of data in C language?
- What are the different data types of arrays in C#?
- What are primitive data types in Java?
- What are reference data types in Java?

Advertisements