Effective C# 第五章:和Framework一起工作(译)

Effective C# 第五章:和Framework一起工作
Chapter 5. Working with the Framework

我的同事,也是我的朋友Martin Shoemaker研究一个很严肃的问题,那就是:“我必须写这样的.Net代码吗?” 答案是,也希望是:不。你应该使用你手头上有的,也是你会用的工具来帮助你写代码。

.Net框架是一个很丰富的类库,你对框架学习的越多,你自己要写的代码就越少。框架库会帮你完成很多工作。这一章就告诉你一些.Net框架里最常用的一些技术。当你在.Net框架中有多个选择时,这一章中的一些原则会帮助你选择最好的。你可以使用一些已经存在的东西来写你自己的类和算法,而不应该是与它们相抵触。

这一章中的一些原则反映一些算法和类,当一些开发者可以轻松的使用.Net框架的时候,这是他们决心要自己写的。他们之所以要自己写这些,这是因为,有些时候,.Net框架确实不清楚他们想要什么。这时,我会告诉你如何来扩展已经存在的核心功能。还有一些时候,因为他们不清楚核心时如何工作的;也有时候是因为他们对性能有过高的要求。

即使是使用.框架里所有可用的工具,也有很多的开发人员宁可创建他们自己的工具。千万别写这些代码,特别是已经有人完成了的。
=================
   

Chapter 5. Working with the Framework
My friend and colleague Martin Shoemaker runs a great roundtable called "Do I Have to Write That .NET Code?" The answer is, hopefully, no. You should use all the tools at your disposal to avoid writing code that already exists and that you can use.

The .NET Framework is a rich class library. The more you learn about the framework, the less code you need to write yourself. The framework library will do more of the work for you. This chapter shows you some common techniques to get the most out of the .NET Framework. Other items help you choose the best option when multiple choices are available in the framework. You can write your classes and algorithms to utilize what's already there instead of fighting against it. The items in this chapter reflect the algorithms and classes that developers seem intent on building for themselves when they could easily use the .NET Framework. Sometimes it's because the framework isn't exactly what you need. In those cases, I show you how to extend the core functionality. Sometimes, it's because they don't understand how the core works. Sometimes, it's because they are overly concerned with performance.

Even with all the tools available in the framework, too many developers would rather create their own wheels. Don't write that codeespecially if someone else already did.

 
   

原文地址:https://www.cnblogs.com/WuCountry/p/688893.html