随笔 - 139  文章 - 0  评论 - 421  阅读 - 17万
06 2009 档案
C#中for和foreach循环的性能
摘要:大家先来看看如下三个循环: int[] foo = new int[100]; 1, foreach (int i in foo) Console.WriteLine(i.ToString()); 2,for(int index=0;index<foo.Length;index++) Console.WriteLine(foo[index].ToString()); 3,int len=fo... 阅读全文
posted @ 2009-06-20 15:19 周雪峰 阅读(3055) 评论(5) 推荐(2) 编辑
关于DefaultValueAttribute类的一些误解!
摘要:这个DefaultValueAttributte特性时常令大家比较疑惑,特别是看了MSDN文档中关于这个类的说明,大家可能就更加的疑惑了,文档中关于DefaultValueAttribute特性的说明如下:指定属性 (Property) 的默认值。 所以大家可能都以为通过应用这个特性就会设置属性的默认值,于是大家可能编写了类似的代码: public class Child { private in... 阅读全文
posted @ 2009-06-19 17:00 周雪峰 阅读(319) 评论(1) 推荐(0) 编辑
const,readonly字段的取舍!
摘要:如果想在类中定义某些常量字段,一般有两种选择,可以定义成const,也可以定义成readonly,这两种方式如何取舍呢?在绝大多数情况下,readonly是要优于const的,因为readonly可以带来更大的灵活性!一般我们可以认为const是编译时常量,也就是说你引用const字段,在编译的时候就被替换成相应的常量值了!例如:public class MyClass{ public const... 阅读全文
posted @ 2009-06-17 18:44 周雪峰 阅读(376) 评论(0) 推荐(0) 编辑
公有字段和属性的选择!
摘要:一般在C#中,想“暴露”类中的某些数据给用户可以使用两种方式来实现,一种是使用公有字段,另外一种是使用属性来实现,下面我列举一些代码来比较这两种实现:1,使用公有字段:public class Student{ public string Name;} 2,使用属性: public class Student { private string _name; public ... 阅读全文
posted @ 2009-06-15 15:08 周雪峰 阅读(486) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示