摘要:
有时我们可以需要拼接数组,下面介绍拼接数组的几种方法:1,使用数组的CopyTo方法:int[] array1 = new int[2];int[] array2 = new int[5];int[] result = new int[array1.Length + array2.Length];array1.CopyTo(result, 0);array2.CopyTo(result, arra... 阅读全文
摘要:
如果想在类中定义某些常量字段,一般有两种选择,可以定义成const,也可以定义成readonly,这两种方式如何取舍呢?在绝大多数情况下,readonly是要优于const的,因为readonly可以带来更大的灵活性!一般我们可以认为const是编译时常量,也就是说你引用const字段,在编译的时候就被替换成相应的常量值了!例如:public class MyClass{ public const... 阅读全文
摘要:
一般在C#中,想“暴露”类中的某些数据给用户可以使用两种方式来实现,一种是使用公有字段,另外一种是使用属性来实现,下面我列举一些代码来比较这两种实现:1,使用公有字段:public class Student{ public string Name;} 2,使用属性: public class Student { private string _name; public ... 阅读全文