C#中的静态类
C#静态类无法实例化,只能具有静态成员。C#中的静态类是密封的,不能包含实例构造函数。
以下是带有静态类和静态成员的示例-
示例
using System;
public static class Demo {
public static float PI = 3.14f;
public static int calc(int n){return n*n;}
}
class Program {
public static void Main(string[] args) {
Console.WriteLine("PI: "+Demo.PI);
Console.WriteLine("Square: " + Demo.calc(3));
}
}输出结果
PI: 3.14 Square: 9
上面的静态类是-
public static class Demo {
public static float PI = 3.14f;
public static int calc(int n){return n*n;}
}上面我们有以下静态成员-
public static float PI = 3.14f;
public static int calc(int n){return n*n;}热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短