static void StringAndNumberType()
{
string strValue = "100";
int intValue = int.Parse(strValue);
double doubleValue = double.Parse(strValue);
intValue = Convert.ToInt32(strValue);
doubleValue = Convert.ToDouble(strValue);
strValue = intValue.ToString();
strValue = doubleValue.ToString();
strValue = 200.ToString();
strValue = intValue + "";
}
从内存模型角度,C#变量可分为以下两种类型
- 值类型(Value Type):int、double...(值类型变量存活于“线程堆栈”中)
- 引用类型(Reference Type):string...(引用类型所引用的对象,生存于“堆”中)