c#基础

来源:互联网 发布:linux用户设置密码 编辑:程序博客网 时间:2024/04/27 18:27

1.声明abstract class中例如public abstract void Updata(),然后在具体的类中重写的时候需要写成public override void Updata();

 

2.class 的实例。例如Boss zhengyue=new Boss(参数);

 

3.属性的使用例子

public string hername

{

get {return name;///name为之前定义的变量等}

set {name=value;}

}

在使用属性的时候就应该是类的实例.hername=“shabi”;

 

4.FileStream为使用字节流,例如在操作字符串的时候需要首先将字符串转换为字符数组,然后通过编码方法转换为字节数组,之后才能操作。

  TextReader和TextWrite为操作字节流的基类,类StreamReader、StringReader由此派生出来。

 

5.在定义数组时格式为char[]  MyChar=new char[100;

   多维数组为int[,]  MyInt=new int[2,3]

  元素为数组的数组称为交错数组,如int[][]  intArray=new int[3][];

  数组的遍历可以使用foreach(),例如上面的交错数组可以使用foreach(int[] number in intArray)

                                                                                                                         {foreach(int i in number)

                                                                                                                            {console.writeline(“大方大方”)}      }

6.哈希表的遍历为foreach(DictionaryEntry my in MyHashTable),其中DictionaryEntry为一个结构体,定义了一个键值对,他可以添加到一个Idictionary中,也可以从中删除。

 

7.委托中的参数为不加括号的函数名字。例如首先声明一个委托public delegate double MyDlelgate(double x,double y),在赋值的时候为

   MyDelegate  MD,MD=new  MyDelegate(类.add),其中add为函数。另外还有多播委托,如MyDelegate  MD,MD=new  MyDelegate(类.add),MD+=new MyDelegate(Multiply)。

8.事件处理,如pubic delegate void somedelegate(string sender)////定义委托    public event somedelegate myevent;/////定义事件      myevent(sender)//////事件触发

原创粉丝点击