Showing posts with label Implicit typed variable. Show all posts
Showing posts with label Implicit typed variable. Show all posts

Implicitly Typed local variables in C sharp

It is a new  feature that has been interchosed in C# 3.0. Which allows declaring variable by using the Var keyword and here the data type of those variable is identifiers base in the value that is assigned to it.


            var t = 100; /// t is of type int

            var f = 12.56f //f is a   type float

            var b = true; //b is of type bool

            var s = "csharpatoz"; // s is type string

While declaring implicit type local variable we need to remember two things:-

  1. We can not declare variable using var keyword without initialization those variable.
  2. We can declare this variable only a block of code like a method. But not directly under a class to consume throughout the class.