namespace 内置引用类型
{
class Program
{
static void Main(string[] args)
{
object o = new object();//声明一个object类型,声明时,object既可以是大写也可以是小写,小写object=System.Object=Object
var oo = o.GetType();//获得类型
var ooo = o.ToString();//转为字符串
Console.WriteLine(oo);//结果:System.Object
Console.WriteLine(ooo);//结果:System.Object
}
}
}
object是C#语言所有类型的基类,所以所有的类型都有ToString()方法。
namespace object强制转换
{
class Program
{
static void Main(string[] args)
{
string s = "HelloWorld";
string s2 = "Hello";
s2 += "World";
Console.WriteLine(s2);//HelloWorld
Console.WriteLine(s == s2);//结果为true
Console.WriteLine((object)s == (object)s2);//结果为false
//这里字符串做了一个强制类型转换
char c = s[2];
Console.WriteLine(c);//结果为e
string u = "\\\u0066\n";// “\\”代表Unicode中对应“\”,“\u0066”对应“f”,“\n”对应回车
Console.WriteLine(u);//结果为“\f”加回车
}
}
}