title: Type inference:The initializer in the declaration is used to drive the inference engine,and is required
body: <p>Type inference:The intializer in the declaration is used to drive the inference engine,and is required.The following are thus illegal:</p>
  
  <pre><code>var obj2    ://ERROR :must have an intializer
  var obj3=null   :ERROR   :must have a specific type
  </code></pre>
  
  <p>Assuming the inference is successful,the inferred type becomes permanent and compilation proceeds as usual,Apparent misuses of the type are detected and reported by the compiler:</p>
  
  <pre><code>var obj4 ="hi!";
  obj4.Close();//Oops,wrong object!(Error:'string does not contain' 'Close')
  </code></pre>
  
  <p>Do not confuse var with the concept of a VB varient(its not),nor with the concept of var in dynamic languages like javascript(where var really means object).in these languages the variable's type can change nad so type checking is performed at runtime increased flexibility at the cost of safety.in c# 3.0 the type cannot  change and all type checking is done at compile-time.For example,if the inferred type is object(as for obj6 below),in c# 3.0 you end up with an obect reference of vaery little functionality:</p>
  
  <pre><code>object obj5="hi"; //obj5 references the string "hi!",but type is object
  var obj6    =obj5; //obj6 also references "hi!",with inferred type object
  .
  .
  .
  
  string si=obj6.ToUpper(); //ERROR:'object' does not contain 'ToUpper'
  </code></pre>