![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C# basic
文章平均质量分 59
xutao_ustc
这个作者很懒,什么都没留下…
展开
-
params关键字
<br />语法:<br />1.在方法声明中的 params 关键字之后不允许任何其他参数<br />2.并且在方法声明中只允许一个 params 关键字。 <br />3.param后面的参数必须是一个数组<br />因此可见params参数总是在最后的,且前面的总是平常的参数,或者前面没有参数。<br />public static void fun(params int[] array)<br />public static void fun(int param,params int[]原创 2011-05-17 23:12:00 · 761 阅读 · 0 评论 -
流(2)--流
BinaryReader,BinaryWriter--可以看见它的方法Writer的方法主要有--Seek主要用来选取插入的位置,Write方法重载了写入bool,decimal,double,float,int,long,sbyte,short,string,unit,ulong,ushort,byte,byte[],char,char[]的方法。可以看见其中的几个方法--PeekChar,Read,Readxxx,对于byte和char有Readxxxs。Readxxx和Readxxxs行为基本一致,读原创 2011-05-28 23:53:00 · 579 阅读 · 0 评论 -
C#用字符串触发事件
接口可以声明事件,实现接口的时候写法如下:要再写一遍,并加上public关键字。public delegate void Func(); public interface B { event Func ff; } public class CC : B { public event Func ff; }事件在声明的类当中,是当做委托来看待的,它和委托拥有完全一样的方法和属性。但是事件在外部,基本什么也不能做,仅能+=和-=注册和取消原创 2011-05-30 21:21:00 · 2082 阅读 · 0 评论 -
多线程
Threads are responsible for multitasking within a single application.You may never need to manage threads explicitly,because the CLR abstracts much of the thread support into classes that simplify most threading tasks.Even if you don`t create your own thr原创 2011-05-31 18:29:00 · 445 阅读 · 0 评论 -
集合
1.数组每个实例化的数组都继承于Array抽象类,Array抽象类实现了IEnumerable,ICollection,IList接口。其中不是每一个方法都实现了,没有实现的抛出异常。2.List,ArrayListpublic class List : IList, ICollection, IEnumerable, IList, ICollection, IEnumerable注意删除元素的时候,先看IEquatable接口,在看重写的Object的equals方法,再看引用。AsReadOnly()可原创 2011-06-01 18:03:00 · 661 阅读 · 0 评论 -
C#拾遗
<br />1.考虑用if-return,取代if-else<br />2.string.Join(",",array). 当数组长度大于1的时候, 在每个元素之间加上分隔符,就算元素是null或者""也一样。若长度为1,直接返回元素,若为null返回“”,当长度为0时,返回""。原创 2011-06-02 10:06:00 · 390 阅读 · 0 评论 -
关于异常
几个关键字:try,catch,finally,throw,throw 具体异常.在try,catch,finally中都可以嵌套try,catch,finally结构.在try,catch,finally中发生了异常都会跳转,跳转点以后的代码就不会执行了。catch是可以不写的,那么如果不写异常得不到处理,看看结果。class Program { st原创 2011-06-04 11:45:00 · 462 阅读 · 0 评论 -
C#初始化过程
class Program { static void Main(string[] args) { new D(); } } class B { private static int b_s_int = fun(); private int b_int原创 2011-06-05 00:31:00 · 592 阅读 · 0 评论 -
Windows 服务
Windows服务是指操作系统可以启动运行的程序。编写一个windows服务至少需要以下三个部分:1.服务程序的主体2.服务安装程序,把服务安装到系统中,完成一些写注册表的操作。3.服务控制程序,用代码控制服务的开关启停。我们来看看第一个部分:做法为:1.创建一个项目,类型为Windows服务。单击ok以后,系统给我们生成了一个模板。一个program.cs和一个Service1.cs。双击Service1.cs会出现一个外观与windows Forms应用程序类似的设计器。双击这个文件,会在右下角出现pr原创 2011-04-25 13:06:00 · 750 阅读 · 0 评论 -
C# 如何执行bat文件 传参数
<br />Process p = new Process();string path = ...;//bat路径ProcessStartInfo pi= new ProcessStartInfo(path, ...);//第二个参数为传入的参数,string类型以空格分隔各个参数pi.UseShellExecute = false;pi.RedirectStandardOutput = true;p.StartInfo = pi;p.Start();p.WaitForExit原创 2011-04-25 18:55:00 · 11562 阅读 · 0 评论 -
yield用法
class Program { static void Main(string[] args) { Test test = new Test(); foreach (var item in test) //对应于GetEnumerator { Console.WriteLine(item); } fo原创 2011-04-24 00:02:00 · 3426 阅读 · 0 评论 -
索引器
<br />索引器的格式为 类型 this[类型 参数]{get;set;} 其中类型参数的类型可以多变,也可以有多个参数<br /> <br /> <br />class Program { static void Main(string[] args) { Test test = new Test(); Console.Write(test[1,1]); Console.Re原创 2011-04-24 11:20:00 · 424 阅读 · 0 评论 -
C# 析构
对象不用的时候,可能会有它占用的资源需要释放(文件句柄,网络连接,数据库连接),为了释放非托管资源,一般有两种方式:1,申明一个析构函数2,在类中执行IDisposable接口public class MyClass { ~MyClass() { Console.WriteLine("xuxu"); } }第一种方式,编译器会把析构函数编译成Finalize(),看来是一种好的地方放置释放资源的地方。但是析构函数具有不确定性,它是在垃圾原创 2011-04-24 19:12:00 · 566 阅读 · 0 评论 -
继承的一些问题
<br /> class Program { static void Main(string[] args) { Derive derive = new Derive(); derive.fun(); } } public class Data { int a; public Data() {原创 2011-05-30 16:31:00 · 394 阅读 · 0 评论 -
属性和反射
Metadata is information about the data that is information about the types ,code, assembly and so forth stored along with the program.Attributes are a mechanism for adding metadata,such as compiler instructions and other data about your data,methods and cl原创 2011-05-29 20:35:00 · 801 阅读 · 1 评论 -
c#的事件
<br />http://www.cnblogs.com/michaelxu/archive/2008/04/02/1134217.html<br />http://www.cnblogs.com/jimmyzhang/archive/2007/09/23/903360.html<br />请看这两个人的博客。原创 2011-05-17 15:54:00 · 320 阅读 · 0 评论 -
wait to read
<br />yield <br />thread<br />reflection原创 2011-05-18 22:31:00 · 363 阅读 · 0 评论 -
类型转换
PS:图应该横向看,特殊标记表示可能有精度丢失。不存在任何到char的隐式转换。原创 2011-05-21 00:53:00 · 319 阅读 · 0 评论 -
操作符重载
<br />class Number { private int val; public Number(int val) { this.val = val; } public static Number operator +(Number lhs, Number rhs) { return new Number(lhs.val + rhs.val); }原创 2011-05-21 11:10:00 · 357 阅读 · 0 评论 -
C#结构体
与类的相同点:都有构造方法,属性,方法,字段,操作符,嵌套类型和索引器与类的不同点:不支持继承(但可以实现接口)和析构函数,而且结构是一种值类型。不能有自定义无参构造函数,如果我们不定义构造函数,字段将初始化为默认值,如果我们写了有参构造函数,则必须要在构造函数里面初始化所有的值。 不能初始化字段(如private int num =1;)结构体集合的效率不好,因为集合元素的类型是引用类型的,这样结构装入会有装箱和拆箱操作。[access level] struct name[:接口]{}原创 2011-05-21 11:48:00 · 371 阅读 · 0 评论 -
接口
接口里面可以声明方法,属性,索引器,事件。不支持field。组合接口 interface I1:I2,I3原创 2011-05-21 12:22:00 · 415 阅读 · 0 评论 -
异常
C#中是没有throws关键字的。。finally中如果抛出异常,则无法保证finally能全部执行完毕。finally中不能写return。重新抛出异常:可能抛出同一异常,这样就直接写throw就可以,也可能抛出不同的异常,如果要包含原始异常的信息,要把原异常封装到新异常中,并在新异常的InnerException属性可以访问原异常。原创 2011-05-22 01:20:00 · 444 阅读 · 0 评论 -
委托与事件
暴露对外的事件或者委托实例,如果没有订阅的方法,那么将为null所以要这么写if (onWaterBoiled != null) onWaterBoiled();采用事件而不是委托的好处是:如果采用委托实例,那么外界可以改变这个委托指向的方法。一句话就是破坏了封装性。而且严重的事情是,外界本来获得这个事件或者委托的实例是用来注册,但是一旦采用委托实例来做,那么没有办法阻止外界触发。。原创 2011-05-22 01:32:00 · 416 阅读 · 0 评论 -
获取Type的方式
<br />string的clone方法返回的是原string的引用,这是为什么呢?因为string是不可变的,clone保证的是两个对象是状态独立的,一个对象状态的改变不会影响到另外一个对象,而string是状态不可变的,所以直接返回引用没有问题。<br />返回Type的方法:<br />namespace ConsoleApplication7{ class Program { static void Main(string[] args)原创 2011-05-23 14:54:00 · 606 阅读 · 0 评论 -
C#3.0新特性
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { Person person = new Person() { ID = 1, Nam原创 2011-04-05 11:14:00 · 389 阅读 · 0 评论 -
C# 4.0
<br />1.方法默认参数,that optional parameters must appear after all required parameters,且值在编译时确定<br />public void fun(string a, string b = "xuxu"){ }<br />2.named parameters--With named parameters it is possible for the caller to explicitly identify t原创 2011-05-25 10:10:00 · 488 阅读 · 0 评论 -
流(1)--文件
For many applications,data is held in memory and accessed as if it were a three-dimensional solid;when you need to access a variable or an object ,use its name and it is available to you.When you want to move your data into or out a file,across the network原创 2011-05-27 20:52:00 · 530 阅读 · 0 评论 -
C# 序列化
<br />这个人的文章很好<br />http://www.cnblogs.com/daniel206/archive/2008/01/16/1042123.html<br />class Program { static void Main(string[] args) { List<XuXu> list = new List<XuXu>(); list.Add(new XuXu(){ID=1,Name="原创 2011-05-06 13:47:00 · 415 阅读 · 0 评论