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.

1 comment:

  1. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.C Sharp Programming Online Courses In Myanmar

    ReplyDelete