Skip to main content

Posts

Showing posts with the label The keyword ‘var’

The keyword ‘var’ in C#?

The keyword ‘var’ what it is in C#? The var keyword was introduced C# 3.0, used to declare the implicitly typed local variables without specifying an explicit type and the type of local variables will automatically be determined by the compiler based on the right-side value of initialization statement.   The two declarations below are functionally equivalent in C#.   // Implicitly typed var x = 50; // Explicitly typed int y = 50; As discussed above, the compiler will automatically infer the type “ integer ” to the variable  x  based on the right side value  50 .   Var Keyword Example The examples show the various ways of declaring the implicitly typed local variables with var keyword in C#.   using System; namespace CsharpnaijaTutorial {     class Program     {         static void Main( string [] args)       ...