C# Error CS0818 – Implicitly-typed variables must be initialized

C# Error

CS0818 – Implicitly-typed variables must be initialized

Reason for the Error & Solution

Implicitly typed locals must be initialized

An implicitly typed local variable must be initialized with a value at the same time that it is declared.

To correct this error

  1. Assign a value to the variable or else give it an explicit type.

Example

The following code generates CS0818:

// cs0818.cs  
class A  
{  
    public static int Main()  
    {  
        var a; // CS0818  
        return -1;  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...