Essential C# C# 3.0 Features  Suggest an edit

Implicitly typed variables var

The var keyword allows a programmer to implicitly type a variable at compile time. var declarations have the same type as explicitly declared variables.

var squaredNumber = 10 * 10;
var squaredNumberDouble = 10.0 * 10.0;
var builder = new StringBuilder();
var anonymousObject = new
    One = SquaredNumber,
    Two = SquaredNumberDouble,
    Three = Builder

The types of the above variables are int, double, StringBuilder, and an anonymous type respectively.

It is important to note that a var variable is not dynamically typed. SquaredNumber = Builder is not valid since you are trying to set an int to an instance of StringBuilder

Table Of Contents
22 Enum
74 C# 3.0 Features
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close