Initialize VAR in C# Programming

While working with var in c#, if you need to initialize var, it can be simply done by the following:

  1. var qq=null;  
If we will run the above code snippet, the following error will occur.

error
Image 1.

So to solve this use initialize your var as in the following screenshot.

As you can in the following, we will store a List in var:

List
Image 2.

It depends what you want to store in your list. Use the following if you want string:
  1. string y = null;  
  2. var qq = y;  

 

Ebook Download
View all
Learn
View all