我是.NET编程的新手,有谁能用实时示例向我解释对象实例化?
答案 0 :(得分:5)
object handle = new object();
“handle”不是对象本身,而是对象的句柄。理解这一点非常重要:)你可以拥有同一个对象的多个句柄;例如:
object handle1 = new object(); //Here's the instantiation
object handle2 = handle1; //No instantiation
//These methodcalls happens on the same instance of object.
handle1.ToString();
handle2.ToString();
答案 1 :(得分:3)
new object(); // instantiation
object o; //declaration
o = new object(); // assignment and instantiation
object p = new object(); //all three