可以貼到開發程式碼的軟體上或notepad++語言選C# 看得比較清楚,直接貼到Visual Studio應該看得更清楚
public class ClassOne
{
public static void In()
{
//static情況下不能直接使用同個class的普通Method而是要先new物件才能使用
ClassOne p = new ClassOne();
p.Meth();
//但是如果同class裡的static Method可以直接使用
MethStatic();
}
public void InPlain()
{
Meth();//在普通非static方法範圍中可以直接使用同class的普通方法
MethStatic();//普通方法範圍中也可直接使用同class static method
}
public void Meth() { }
static public void MethStatic() { }
}
public class ClassOut//在ClassOne之外的範圍中測試ClassOne裡的方法的使用規則
{
//不能直接使用同namespace的其他普通class裡的方法 普通class內的static方法也不行
//但static meth可用 "class點static方法名稱" 的方式直接使用
//但是要在方法裡才能使用,不能在class中方法範圍外class範圍內的中間地帶使用
public void Test()
{
ClassOne.MethStatic();
ClassOne.In();
}
//而普通方法要new才能使用,相反的new之後倒是不能用物件點static方法
public void Test2()
{
ClassOne c = new ClassOne();
c.Meth();
c.InPlain();
}
}
全站熱搜