namespace lover_P.Test { 
public class Test {
public void InstanceMethod() {} // 实例成员(非静态)
public static void StaticMethod {} // 类型成员(静态)
public static void Main() {
InstanceMethod(); // 错误!调用了实例成员,而此时并没有建立实例
StaticMethod(); // 正确!可以调用静态成员
Test SomeTest = new Test(); // 建立本类型的一个实例
SomeTest.InstanceMethod(); // 再在这个实例上调用实例成员就对了
SomeTest.StaticMethod(); // 附加一句,在实例上调用静态成员也是错误的!
}
}
}

相关文章:

  • 2021-07-26
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-03-07
猜你喜欢
  • 2021-11-29
  • 2021-10-30
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案