静态方法-C#教程实用版 ppt

时间:2021-04-23 19:46:42
【文件属性】:
文件名称:静态方法-C#教程实用版 ppt
文件大小:4.81MB
文件格式:PPT
更新时间:2021-04-23 19:46:42
C#教程实用版 ppt 静态方法 类方法是不需要类的任何实例就可以被调用的方法,在方法声明中用static关键字表示。 类方法只能访问静态变量,访问非静态变量的尝试会引起编译错误。 静态方法不能被覆盖成非静态的。 main是静态的,因为它必须在任何实例化发生前被访问,以便应用程序的运行。 public class GeneralFunction { public static int AddUp(int x, int y) { //静态方法 return x + y; } } public class UseGeneral { public void method() { int c = GeneralFunction.AddUp(9, 10); //调用静态方法 System.Console.WriteLine("addUp() gives " + c); } }

网友评论