This error might come when you use the var
keyword in the C# language. Following is the statement that gives me the error.
var message;
Error
error CS0818: Implicitly-typed variables must be initialized
Fix
To give you a background. You can only use the var
keyword if the variable is initialized. You can see the statement that we have used. We did not initialize the message
.
The var
keyword is dependent on the value you use to initialize the variable. These are the Implicitly typed local variables that are created using the var
keyword.
In the below example, we will declare a variable using the var
keyword instead of the string
keyword.
var message = "Hello world!";