关于静态类“static-class.static-member”与“class.static-member”,
以下两个类有什么区别呀?//class with static prefix
public static class test()
{
public static string getHello(){}
}//class without static hat
public class test()
{
public static string getHello(){}
}这样写好像也能通过(一个静态成员,一个非静态成员)
//class without static hat, member..
public class test()
{
public static string getHello(){}
public string getWorld(){}
}
以下两个类有什么区别呀?//class with static prefix
public static class test()
{
public static string getHello(){}
}//class without static hat
public class test()
{
public static string getHello(){}
}这样写好像也能通过(一个静态成员,一个非静态成员)
//class without static hat, member..
public class test()
{
public static string getHello(){}
public string getWorld(){}
}
msdn? 宝贵的硬盘空间,为何不拿来装move-ice?
public class test
{
public static string aaa { get; set; }
public string bbb { get; set; } public static string getHello() { return "Hello"; }
public string getWorld() { return "World"; } private void ccc()
{
//实例化并操作
test tt = new test();
tt.bbb = ""; //
tt.getWorld(); //
tt.ccc(); //
//操作静态成员
test.aaa = ""; //
test.getHello(); //
}
}
现在改了,不是死循环了。下面代码证明test类即可以实例化来使用,又可以静态地使用,这样有什么不妥?或有什么用?为什么可以这样写。
public class test
{
public static string aaa { get; set; }
public string bbb { get; set; } public static string getHello() { return "Hello"; }
public string getWorld() { return "World"; } private void ccc()
{
//实例化并操作
test2 tt = new test2(); //注:test2的结构与test基本相同
tt.bbb = ""; //
tt.getWorld(); //
tt.ccc(); //
//操作静态成员
test2.aaa = ""; //
test2.getHello(); //
}
}
普通类既可定义静态成员,还可定义实例成员,可以被继承,也可以实例化
我觉得不是,就像汇编指令中的 [xor AX, AX] 与 [nop] 看起来是等效的一样。
(记不清了,好像不是[xor ax,ax],这指令占两个time,而nop只占一个time,然道是[mov ah, ah]与空指令等效?)。
[static class]与[abstract and sealed class]应该讲也是同样道理,位置被占了,所以后者不存在。