C# Language Visual C# .NET (C#) is relatively easy to learn for anyone familiar with another object-oriented language. Even someone familiar with Visual Basic 6.0, who is looking for an object-oriented language, will find C# easy to pick up. However, although C#, coupled with the .NET Framework, provides a quick path for creating simple applications, you still need a wealth of information and must understand how to use it correctly in order to produce sophisticated, robust, fault-tolerant C# applications. In Accelerated C# 2008 I teach you what you need to know and explain how best to use your knowledge so that you can quickly develop true C# expertise.39515
Idioms and design patterns are invaluable for developing and applying expertise, and I show you how to use many of them to create applications that are efficient, robust, fault tolerant, and exception safe. Although many of these patterns are familiar to C++ and Java programmers, some are unique to .NET.
C#, like C++ and analogous to Java packages, supports namespaces for grouping components logically. Namespaces help you avoid naming collisions between your identifiers. Using namespaces, you can define all of your types such that their identifiers are qualified by the namespace that they belong to. You have already seen namespaces in action in many of the examples so far. For instance, in the “Hello World!”, you saw the use of the Console class, which lives in the .NET Framework Class Library’s System namespace and whose fully qualified name is System.Console. You can create your own namespaces to organize components. The general recommendation is that you use some sort of identifier, such as your organization’s name, as the top-level namespace, and then more specific library identifiers as nested namespaces.
Namespaces provide an excellent mechanism with which you can make your types more discoverable, especially if you’re designing libraries meant for consumption by others. For example, you can create a general namespace such as MyCompany. Widgets, where you put the most commonly used types of widgets. Then you can create a MyCompany. Widgets. Advanced namespace where you place all of the less commonly used, advanced types. Sure, you could place them all in one namespace. However, users could become confused when browsing the types and seeing all of the types they least commonly use mixed in with the ones they use the most.
Lambda expressions make it easy to declare and instantiate function delegates at one point. Additionally, with lambda expressions, the new language features in C# 3.0 foster an environment where functional programming can flourish interweaved with the typical imperative programming style of C#. LINQ allows you to express data query operations iwhich are typically functional in nature) using a syntax that is native to the language.
Support for generics is one of the most exciting new additions to the C# language. Using the generic syntax, you can define a type that depends upon another type that is not specified at the point of definition, but rather at the point of usage of the generic type. For example, imagine a collection type. Collection types typically embody things such as lists, queues, and stacks. The collection types that have been around since the .NET 1.0 days are adequate for containing any type in the CLR, since they contain Object instances and everything derives from Object. However, all of the type information for the contained type is thrown away, and the compiler’s power to catch type errors is rendered useless. You must cast every type reference that you obtain from these collections into the type you think it should be, and that could fail at run time. Also, the original collection types can contain a heterogeneous blend of types rather than force the user to insert only instances of a certain type. You could go about fixing this problem by writing types such as ListOfIntegers and ListOfStrings for each type you want to contain in a list. However, you will quickly find out that most of the management code of these lists is similar, or generic, across all of the custom list types. The key word is generic. Using generic types, you can declare an open (or generic) type and only have to write the common code once. The users of your type can then specify which type the collection will contain at the point they decide to use it. C#语言英文参考文献和中文翻译:http://www.youerw.com/fanyi/lunwen_39836.html