Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0156 var type variable is static typed

You cannot change the type for a var-type variable. using System; class Program { static void Main(string[] args) { var i = 5; i = "rntsoft.com"; } } The code above has the following error message: C:\g>csc Program.cs Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved. Program.cs(8,13): error CS0029: Cannot implicitly convert type 'string' to 'int'