赋值运算符 (=) 将右操作数的值存储在左操作数表示的存储位置、属性或索引器中,并将值作为结果返回。操作数的类型必须相同(或右边的操作数必须可以隐式转换为左边操作数的类型)。
备注
示例
| 复制代码 |
---|
// cs_operator_assignment.cs
using System;
class MainClass
{
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);
}
} |
输出
|
---|
i is 5, x is 5
boxed value = 5, type is System.Int32
unboxed: 5 |
请参见