Null Conditional Operator in Visual Studio 2015

Introduction

Recently  there was a great announcement in the Visual Studio connect() event by Microsoft. Many things were introduced there like Visual Studio 2015, C# 6 and many more. Here I am trying to explain a common feature, the null conduction operator, that is in C# 6. In this feature we have the special keyword "?" . This keyword denotes the null conduction operator.

As we have seen, the null condition operator uses has.value but that is quite cumbersome. From my point of view let us try to understand it with an example and I will also try to compare it with the old one.

The Null Conditional Operator returns the value that can be undefined. This is a type of data set. A data set is a collection of the data type and stores many data tables in a single collection. In the null conditional operator the default value is a reference type variable.

Program of input Null Conduction operator

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace null_value1  
  8. {  
  9.     class program  
  10.   
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             int? x = 3;  
  15.             int y = 3;  
  16.             Console.WriteLine();  
  17.             bool check = false;  
  18.             if (y == x)  
  19.             {  
  20.                 Console.WriteLine();  
  21.                 check =     true   ;  
  22.                 Console.WriteLine(check.ToString());  
  23.                 Console.ReadLine();  
  24.             }  
  25.   
  26.         }  
  27.     }  
  28. }   

Output of this program


Visual Studio Library show the error

 

Old version of Null Conduction operator

In the null value, suppose you enter a integer value that is a special case like 0. In many programming languages that can mean false. But the null function helps to enter the special case of values. They are some type of null value. 1 Hasvalue is the return, a bool and indicates the null value contains a set value. It does not have the value. The null hasvalue is false, also the assigned only has an integer value. With the hasvalue is true <T>. You can easily access the value without any exception.2 Value property is used for the return value if only one is assigned but the default value for the has.value is false. The value property has no default value.

Input program of Null Conduction operator 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace null_value1  
  8. {  
  9.     class program  
  10.   
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             int x = 5;  
  15.             int y = 3;  
  16.             Console.WriteLine();  
  17.             bool check = true;  
  18.             if (y == x)  
  19.             {  
  20.                 Console.WriteLine();  
  21.                 check =     false   ;  
  22.                 Console.WriteLine(check.ToString());  
  23.                 Console.ReadLine();  
  24.             }  
  25.   
  26.         }  
  27.     }  
  28. }  
  29.   
  30.      

Output of program

 
Summary

Microsoft  added the new feature in Visual Studio 2015 on 13 Nov, 2014.They used only this ? symbol of the null conduction operator to implement the program and show the output.


Similar Articles