学习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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值