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 = "java2s.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'
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.