A Tutorial: Learn How to Avoid The 10 Most Common C# Mistakes笔记
来源:互联网 发布:八爪鱼采集器mac版 编辑:程序博客网 时间:2024/04/28 22:13
感觉比较重要的需要注意的陷阱总结了下:
基础语言特性:
1.C#是强数据类型的,注意引用和值类型区别。
2.C#中提供的默认值和C++相反,C#中数据成员提供默认值,局部方法中不提供默认值。
.net字符串操作和内存管理:
3.string类型比较不能用==符号,而应该用Equals方法。
Console.WriteLine(s == "straße");Console.WriteLine(s.Equals("straße"));
Console.WriteLine(s.Equals("straße", StringComparison.Ordinal));
Console.WriteLine(s.Equals("Straße", StringComparison.CurrentCulture));
Console.WriteLine(s.Equals("straße", StringComparison.OrdinalIgnoreCase));
// outputs True:
Console.WriteLine(s.Equals("straße", StringComparison.CurrentCulture));
Console.WriteLine(s.Equals("Straße", StringComparison.CurrentCultureIgnoreCase));
其实字符串还有不能频繁截取创建,这个时候应该要用BuilderString来做。
4.非托管堆资源的释放,例如文件描述符,数据库连接,网络连接等
需要考虑析构函数或Finalize方法,而且析构函数是会推迟执行的,所以需要继承IDisposable接口,实现Dispose()方法,对象超过生命期会马上释放。保持这些资源使用状态会急剧耗尽系统的资源,削弱性能并且最终导致程序出错。
LINQ数据查询语言(底层对象多样)和数据结构(泛型优势):
5.LINQ对象类型不一样,会有不同的结果,比如是SQL的对象,XML对象,或者内存容器的对象。
6.正确使用容器类型,且用泛型类型的容器类型可以比非泛型的有更高的性能,因为避免了装箱和拆箱操作。
Array,ArrayList,BitArray,BitVector32,Dictionary<K,V>,HashTable,HybridDictionary,List<T>,NameValueCollection,OrderedDictionary,Queue, Queue<T>,SortedList,Stack, Stack<T>,StringCollection,StringDictionary.
原文见:http://www.toptal.com/c-sharp/top-10-mistakes-that-c-sharp-programmers-make
http://www.oschina.net/translate/top-10-mistakes-that-c-sharp-programmers-make
0 0
- A Tutorial: Learn How to Avoid The 10 Most Common C# Mistakes笔记
- Web Bloopers: 60 Common Web Design Mistakes, and How to Avoid Them
- 10 Most Common Mistakes that Python Programmers Make
- How to avoid common errors and make program efficient.
- The 10 Mistakes Most Men Make With Women
- How to avoid Conflict
- How to Avoid Falling Into the Phishing Hole
- How to avoid the mistake during phone interview
- How to avoid the "enumeral mismatch" error in eikmenup.h
- Just learn how to use the JNI
- learn how to learn
- learn how to learn
- How to learn a book more effect?
- Q&A:How To Learn Computer Graphic
- How to Learn a Programming Language
- How to learn a complex system(draft)
- SVN: How to resolve a conflict tutorial
- How to Use Java BigDecimal: A Tutorial
- bootstrap+css属性
- 杭电oj-2544-最短路
- redis安装
- 数据结构(七)链表
- C++STL之string下
- A Tutorial: Learn How to Avoid The 10 Most Common C# Mistakes笔记
- C结构体之位域(位段)
- 验证歌德巴赫猜想对2000以内的正偶数成立 及 将一个正整数分解质因数
- IOS 异步下载图片
- 开源中国源码学习UI篇(三)之ViewPager+Fragment的使用分析
- Android.mk简介
- lintcode-矩阵的之字型遍历 -185
- JSON对象长度和遍历方法
- iOS编程------UIAlertController