= 运算符(C# 参考)

更新:2007 年 11 月

赋值运算符 (=) 将右操作数的值存储在左操作数表示的存储位置、属性或索引器中,并将值作为结果返回。操作数的类型必须相同(或右边的操作数必须可以隐式转换为左边操作数的类型)。

备注

不能重载赋值运算符。

示例

class Assignment
{
    static void Main()
    {
        double x;
        int i;
        i = 5; // int to int assignment
        x = i; // implicit conversion from int to double
        i = (int)x; // needs cast
        Console.WriteLine("i is {0}, x is {1}", i, x);
        object obj = i;
        Console.WriteLine("boxed value = {0}, type is {1}",
                  obj, obj.GetType());
        i = (int)obj;
        Console.WriteLine("unboxed: {0}", i);
    }
}
/*
Output:
i is 5, x is 5
boxed value = 5, type is System.Int32
unboxed: 5
 */

请参见

概念

C# 编程指南

参考

C# 运算符

其他资源

C# 参考