第一部分是语言使用的基础,而这是使用语言的基本功,也是平常最不注意的,养成好的习惯,有利于后期水平提高。这部分包括11个单元,分别如下:
Item 1: Always Use Properties Instead of Accessible Data Members
《Effective C#》Item 1:用属性来访问类的私有成员
http://blog.csdn.net/knight94/archive/2006/06/04/772886.aspxItem 2: Prefer readonly to const
《Effective C#》Item 2:定义常量的两种方法
http://blog.csdn.net/knight94/archive/2006/06/06/776548.aspxItem 3: Prefer the is or as Operators to Casts
《Effective C#》Item 3:使用as和is操作符来做类型转换
http://blog.csdn.net/knight94/archive/2006/06/12/791850.aspxItem 4: Use Conditional Attributes Instead of #if
《Effective C#》Item 4:使用Conditional属性来代替IF/ENDIF程序块
http://blog.csdn.net/knight94/archive/2006/06/18/809479.aspxItem 5: Always Provide ToString()
《Effective C#》Item 5:提供一个有意义的ToString函数
http://blog.csdn.net/knight94/archive/2006/06/18/810467.aspxItem 6: Distinguish Between Value Types and Reference Types
《Effective C#》Item 6:区分值类型和引用类型
http://blog.csdn.net/knight94/archive/2006/07/01/861383.aspxItem 7: Prefer Immutable Atomic Value Types
《Effective C#》Item 7:推荐使用不可改变的原子值类型
http://blog.csdn.net/knight94/archive/2006/07/27/985552.aspxItem 8: Ensure That 0 Is a Valid State for Value Types
《Effective C#》Item 8:确保"0"在值类型中是有效的
http://blog.csdn.net/knight94/archive/2006/08/09/1040766.aspxItem 9: Understand the Relationships Among ReferenceEquals(), static Equals(),
instance Equals(), and operator==
《Effective C#》Item 9:区别和认识四个判等函数
http://blog.csdn.net/knight94/archive/2006/08/11/1050901.aspx
Item 10: Understand the Pitfalls of GetHashCode()
《Effective C#》Item 10:小心GetHashCode函数所存在的陷阱
http://blog.csdn.net/knight94/archive/2006/08/20/1100194.aspxItem 11: Prefer foreach Loops
《Effective C#》Item 11:提倡使用foreach语句来进行循环操作
http://blog.csdn.net/knight94/archive/2006/08/20/1100236.aspx文章中提到一些好的方法,以及各个方法的细微之处,都是不错的。不过建议大家如果有机会的话,还是买本原书来看。如果文章有什么不当之处,或者对文章有什么好的建议的话,可以来信告诉我,我会在下一部分编写过程中加以注意。至于下部分的进度,为了保证文章的质量,所以我会把一周的文章数控制在三篇以内。
Item 1: Always Use Properties Instead of Accessible Data Members
《Effective C#》Item 1:用属性来访问类的私有成员
http://blog.csdn.net/knight94/archive/2006/06/04/772886.aspxItem 2: Prefer readonly to const
《Effective C#》Item 2:定义常量的两种方法
http://blog.csdn.net/knight94/archive/2006/06/06/776548.aspxItem 3: Prefer the is or as Operators to Casts
《Effective C#》Item 3:使用as和is操作符来做类型转换
http://blog.csdn.net/knight94/archive/2006/06/12/791850.aspxItem 4: Use Conditional Attributes Instead of #if
《Effective C#》Item 4:使用Conditional属性来代替IF/ENDIF程序块
http://blog.csdn.net/knight94/archive/2006/06/18/809479.aspxItem 5: Always Provide ToString()
《Effective C#》Item 5:提供一个有意义的ToString函数
http://blog.csdn.net/knight94/archive/2006/06/18/810467.aspxItem 6: Distinguish Between Value Types and Reference Types
《Effective C#》Item 6:区分值类型和引用类型
http://blog.csdn.net/knight94/archive/2006/07/01/861383.aspxItem 7: Prefer Immutable Atomic Value Types
《Effective C#》Item 7:推荐使用不可改变的原子值类型
http://blog.csdn.net/knight94/archive/2006/07/27/985552.aspxItem 8: Ensure That 0 Is a Valid State for Value Types
《Effective C#》Item 8:确保"0"在值类型中是有效的
http://blog.csdn.net/knight94/archive/2006/08/09/1040766.aspxItem 9: Understand the Relationships Among ReferenceEquals(), static Equals(),
instance Equals(), and operator==
《Effective C#》Item 9:区别和认识四个判等函数
http://blog.csdn.net/knight94/archive/2006/08/11/1050901.aspx
Item 10: Understand the Pitfalls of GetHashCode()
《Effective C#》Item 10:小心GetHashCode函数所存在的陷阱
http://blog.csdn.net/knight94/archive/2006/08/20/1100194.aspxItem 11: Prefer foreach Loops
《Effective C#》Item 11:提倡使用foreach语句来进行循环操作
http://blog.csdn.net/knight94/archive/2006/08/20/1100236.aspx文章中提到一些好的方法,以及各个方法的细微之处,都是不错的。不过建议大家如果有机会的话,还是买本原书来看。如果文章有什么不当之处,或者对文章有什么好的建议的话,可以来信告诉我,我会在下一部分编写过程中加以注意。至于下部分的进度,为了保证文章的质量,所以我会把一周的文章数控制在三篇以内。
解决方案 »
- <script>中textbox报错,“textbox未定义”,急
- wcf 客户端 同时多次访问服务器一般会卡住,为什么?
- 我用C#做了个小程序,里面包含datagridview控件,我希望能做个保存按钮
- c# 网络socket编程问题,请各位老大进来看看
- 正则表达式的问题
- C#计算器的小问题~急!!!
- ServicedComponent的Deactivate事件是何时触发的?
- 请问我对WebService和net Remoting的区别的理解对吗?如不正确,请帮忙指正一下,谢谢!
- World Wide Web Publishing Service 总是手工 Start 后过不到1分钟它又自动 Stop
- PrivateKey=new string('0',1);这行代码什么意思?----马上揭贴!
- SQL不释放内存的问题!请高手指点!
- DataGrid里这个怎么写?
要是做成chm就更加方便了!
1、原文的关键内容;
2、关键点的对比;
3、实战中类似常见问题地分析和处理。
======
呵呵,我没有其它意思,当然支持愚翁的无私奉献,3Q3Q~~~
=================================能做成 chm文件啊,那就非常非常谢谢
呵呵
1、Form问题;
2、Ado.net和DataGrid操作问题;
3、线程操作问题;
4、Stream操作问题;
5、Dll关联问题。如果有人对这几方面问题有什么好的建议或者好的方法,可以发信告所我
地址:
[email protected]:
文章我会陆续放到我的blog上,等全部结束后,会发帖子通知大家!
一直是我学习的榜样,有这样的老大,开心
Item 11: Prefer foreach Loops
《Effective C#》Item 11:提倡使用foreach语句来进行循环操作
http://blog.csdn.net/knight94/archive/2006/08/20/1100236.aspx关于这个篇章, 我做了一下实验:
(其中 Utility.UtilDateTime.getTimeGap(dt1, dt2) 是我写的一个函数, 输出时间差.)结果:
foreach性能是最差的(差不多用了2倍时间), 第一种和第二种几乎没差别(第二种似乎稍快). private void button1_Click(object sender, System.EventArgs e) {
DateTime dt1=DateTime.Now; int[] arr=new int[50000000];
int result=0;
for(int i=0; i<arr.Length; i++){
result++;
}
Console.WriteLine(result); DateTime dt2=DateTime.Now;
Console.WriteLine(Utility.UtilDateTime.getTimeGap(dt1, dt2)+"ms");
} private void button2_Click(object sender, System.EventArgs e) {
DateTime dt1=DateTime.Now; int[] arr=new int[50000000];
int result=0;
int length=arr.Length;
for(int i=0; i<length; i++){
result++;
}
Console.WriteLine(result); DateTime dt2=DateTime.Now;
Console.WriteLine(Utility.UtilDateTime.getTimeGap(dt1, dt2)+"ms");
} private void button3_Click(object sender, System.EventArgs e) {
DateTime dt1=DateTime.Now; int[] arr=new int[50000000];
int result=0;
foreach(int i in arr) {
result++;
}
Console.WriteLine(result); DateTime dt2=DateTime.Now;
Console.WriteLine(Utility.UtilDateTime.getTimeGap(dt1, dt2)+"ms");
}
foreach(int i in arr) {
result++;
}
和
for(int i=0; i<arr.Length; i++){
result++;
}
的本质区别,前者访问了数组成员,后者没有访问,两者完成的不是同样的操作,怎么具有可比性。如果觉得我所说的有问题,你可以试试
int[] arr=new int[100000000];
int nResult = 0;
Debug.WriteLine( DateTime.Now.ToString() );
nResult = 0;
foreach(int i in arr)
{
nResult += i;
}
Debug.WriteLine( DateTime.Now.ToString() );
nResult = 0;
for( int i = 0; i < arr.Length; i++ )
{
nResult += arr[i];
} Debug.WriteLine( DateTime.Now.ToString() );
就知道什么现象了。
private void button2_Click(object sender, System.EventArgs e) {
DateTime dt1=DateTime.Now; int result=0;
int length=arr.Length;
for(int i=0; i<length; i++){
result+=arr[i];
}
Console.WriteLine(result); DateTime dt2=DateTime.Now;
Console.WriteLine(Utility.UtilDateTime.getTimeGap(dt1, dt2)+"ms");
} private void button3_Click(object sender, System.EventArgs e) {
DateTime dt1=DateTime.Now; int result=0;
foreach(int i in arr) {
result+=i;
}
Console.WriteLine(result); DateTime dt2=DateTime.Now;
Console.WriteLine(Utility.UtilDateTime.getTimeGap(dt1, dt2)+"ms");
}测试结果: 420ms 370ms 420ms 结果的确是第二种最快~ 楼主不信可以做一下, 很简单的三个按钮三个事件.
int length=arr.Length;
for(int i=0; i<length; i++){
result+=arr[i];
}这种操作是最快,查看dissambly,发现它产生的IL并没有像书中所说那样,书中对于这点有出入,我仔细对照一下原文,稍后把这个地方进行修改,然后重新发布上去。再次感谢sozdream!如果有文章有什么问题,都可以提出来讨论!