object 是所有类的基数。
int x=25; object obj1 = x; object obj2 = 'A'; |
string String1 = "Welcome"; string String2 = "Welcome" + " everyone"; char c = String1[0]; bool b = (String1 == String2); |
class PhoneBook{ private string name; // 域 private string phone; private struct address { // 地址结构 public string city; public string phone; public string address; public uint no; }; public string Phone { // 属性 get { return phone; } // 读属性 set { phone = value; } // 设属性 }; public PhoneBook(string n) { // 构造函数 name = n; // 初始化 } public Edit() // 方法 { ; } } |
C# 中使用指针必须表明为 unsafe 非安全的。
相当于函数指针。函数不能有返回值,不能带有输出类型的参数。
delegate int MyDelegate(); public class MyClass { public int InstanceMethod() { ... } public int StaticMethod() { ... } } public class Test { static public void Main() { MyClass p = new MyClass(); MyDelegate d = new MyDelegate( p.InstanceMethod); // 指向非静态的方法 d(); // 调用方法 d = new MyDelegatge( MyClass.StaticMethod ); // 指向静态的方法 d(); // 调用静态方法 } } |
数组长度可自由定义。
int []arr = new int[5]; int []a1 = new int[] { 1,2,3 }; // 定义的赋值 int [,]a2 =new int[,]{ {1,2,3},{4,5,6} } // 二维初值 int [][]j2 = new int[3][]; // 可变维 j2[0] = new int[] { 1,2,3 }; j2[1] = new int[] { 1,2,3,4,5,6 }; j2[2] = new int[] {1,2,3,4,5,6,7,8 }; |