学习C#的一些笔记

接口与类的区别:

1. 不允许使用访问修饰符(public, private, protected或internal),所有接口都必须是公共的。

2. 接口成员不能包含代码体。

3. 接口不能定义字段成员。

4. 接口成员不能使用关键字static, virtual, abstract或sealed(封闭的)来定义。

5. 类型定义成员是禁止的。这点不明白

隐藏基类成员,用关键字

new来定义它们(显示隐藏)

override重写父类中的方法

virtual用来定义虚方法,用来被重写。

调用重写或隐藏基类方法:

base.parentMethod();

this.childMethod();

嵌套类型定义,调用:

MyClass.myNestedClass myObj = new MyClass.myNestedClass();

属性定义:

public int MyInt {get; set;}

partial关键字,将一个类分开-成几个文件

A.cs文件

partial class MyClass

{ public void RtuStrin() {}}

B.cs文件

partial class MyClass

{ public int MyInt; }

C.cs文件

MyClass myClass = new MyClass();

myClass.MyInt = 1;

myClass.RtuStrin();

集合:

ArrayList--容量不是固定的

Animal[] animalArray = new Animal[2];// 定义了固定长度的数组

ArrayList animalArrayList = new ArrayList(); // 未定义固定长度的数组

foreach是IEnumerable接口所支持的

AddRange:向ArrayList中插入一个ArrayList

InsertRange():向ArrayList中插入一个ArrayList指定位置

IList()---->Clear(), RemoveAt();

ICollection---->Count;

Dictionary---->Remove();

Boxing & Unboxing, Nullable, ref, out, param

Delegate Example:

public delegate void DelegateMethod(int number);

public class Test {public DelegateMthod dm; }

public class Test1 { public void Method1 { Console.WriteLine("Test1"); }}

public class Test2 { public void Method2 { Console.WriteLine("Test2"); }}

public class App {

    public static void main() {

        Test t = new Test();

        Test1 t1 = new Test1();

        Test2 t2 = new Test2();

        t.dm += new DelegateMethod(t1.Method1);

        t.dm += new DelegateMethod(t2.Method2);

        t.dm(5);

    }

}

Lock: 线程同步安全,可以锁住某个对象

StringBuilder:

使用继承显示实现接口成员:在方法前面加上接口名称(实现接口某个方法:public interfaceName.methodName())

C#里面的成员可以包括:

字段,属性,方法,事件,运算符,索引器,构造函数,析构函数,嵌套函数

C#中常用的异常类型:

System.Exception;

System.NullReferenceException;

System.ArgumentOutOfRangeException;

System.InvalidCaseException;

路慢慢其休远羲,吾将上下而求所
原文地址:https://www.cnblogs.com/garinzhang/p/3639479.html