Note: Most of this article draws on the "c#5.0 authoritative guide In the Nutshell", small part also wants to comb the C # According to this book well.
Preamble: C # is a common type-safe, object-oriented programming language. The goal of this language is to increase the productivity of programmers, which requires a balance of simplicity, expression, and performance. The chief architect of the C # language, starting with the first version, was Anders Hejlsberg (inventor and Delphi architect of Turbo Pascal). The C # language is platform agnostic, but he works well with the Microsoft.NET framework.
1.1 Object-oriented
C # implements a wide range of object-oriented programming features, including (encapsulation, inheritance, polymorphism). Encapsulation means creating a boundary around an object that isolates his external (public) behavior from the internal (private) implementation details.
C # Features in object-oriented aspects include:
1. Unified Type System
the underlying building block in C # is a package unit of data and functions called types. C # has a unified type system in which all types end up sharing a common base class. This means that all types, whether they are basic types representing business objects or numbers, share the same set of basic features. For example, any type can be converted to a string by calling his ToString method.
2. Class and Interface
In a purely object-oriented generic, the only type is the class. But there are several other types in C #, one of which is an interface (like an interface in Java). The interface is similar to a class, but he has only some type of definition, not the implementation of it. He is very useful when you need to use multiple inheritance (unlike languages such as C + + and Eiffel, C # does not support multiple inheritance of classes (single)).
3. Properties, methods, and Events
in a purely polygon object generic, all functions are methods (that is, in Smalltalk). In C #, a method is just a function member, and it contains properties and events as well as other components. A property is a function member that encapsulates a portion of an object's state, such as the color of a button and the text of a label. Events are function members that simplify the processing of object state changes.
1.2 Type safety
C # is first a type-safe language, which means that only the types are interacting through the protocols they define, guaranteeing internal consistency for each type. For example, C # does not allow string types to be treated as integers.
More specifically, C # supports static typing, which means that the language performs static type security checks at compile time. Another is the dynamic type security, the. NET CLR(CLR Common shorthand word, the CLR is the common language runtime (Common Language Runtime) and a Java virtual machine as well as a runtime environment, which is responsible for resource management ( Memory allocations , garbage collection, etc.), and to ensure necessary separation between the application and the underlying operating system. The CLR has two different translation names: the common language runtime and the common language runtime. performs a dynamic security check at run time.
Static typing can remove a large number of errors before the program. He transfers a large number of running unit tests to the compiler, so the types are mutually appropriate in the validator. This makes large programs easier to manage, more predictable, and more robust. Also, static typing is something like Visual Studio and intellisence that helps you write a program because he knows what type of particular variable it is, and therefore knows what methods can be called to handle it.
Note: C # allows parts of the code to dynamically develop types through the new dynamic keyword. However, C # is a statically typed language in most cases.
C # is known as a strongly typed language because his type rules (performed in a static or dynamic manner) are very strict. For example, a floating-point parameter cannot be used to invoke an integer function that is accepted by a definition unless it is shown to convert the floating-point number to an integer. This also helps in coding errors.
Strong typing is also one of the reasons that C # code can run in the sandbox. An environment in which all aspects of the sandbox's security are controlled by the host. In the sandbox, be aware that you cannot arbitrarily ignore the type rules of an object to break its state.
1.3 Platform Support
C # is typically used to write code that runs on the Windows platform. Although Microsoft's adoption of the ECMA (ECMAScript is an association of the European computer manufacturers , the English name is European computer Manufacturers Association) through ECMA-262 standardized scripting languages . This language is widely used on the World Wide Web , and it is often referred to as JavaScript or JScript, but in fact the latter two are implementations and extensions of the ECMA-262 standard. is standardized for the C # language and the CLR, but is designed to support a relatively small amount of non-Windows platform C # resources, including Microsoft's internal or external. This means that languages such as Java can be a smarter choice if you focus on multi-platform support. Therefore, C # can be used to write cross-platform code in the following situations:
1. C # code runs on the server, generating DHTML that can run on any platform. This is the approach that ASP.
2. C # code runs in a non-Microsoft Common Language Runtime Environment. The most typical is the mono project, which has its own C # compiler and runtime environment that can run on Linux, Solaris, Mac OS x, and Windows.
3. C # code runs on a host that supports Microsoft Silverlight (Windows-enabled and Mac OS X). This is a new technology similar to Adobe Flash player.
1.4 Memory Management
C # relies on the runtime environment to perform automatic memory management. The CLR has a garbage collector that runs as part of the program and is responsible for reclaiming memory that is not in the referenced object. This frees the programmer from having to display the memory allocated for releasing objects, thus avoiding memory problems caused by incorrect use of pointers in languages such as C + +. C # does not remove the pointer: He just makes most of the programming tasks not need pointers. Pointers can still be used for hotspots and interoperability aspects that are critical to performance, but allow for the display of code blocks that are marked as unsafe
1.5 The relationship between C # and the CLR
C # relies on a running environment that includes many features, such as automatic management of memory and exception handling. The design of C # is very close to the CLR's design, and the CLR provides these runtime features (but C # technology does not rely on the CLR). And the C # type system is very close to the CLR's type system (for example, both share the same definition of the underlying type).
1.6 The CLR and the. NET Framework
the. NET Framework consists of a run-time environment called Common Language Runtime (CLR) and a large number of libraries. These libraries consist of a core library and an application library, which relies on the core library. Here is a visual overview of these libraries:
The CLR is the running environment for executing managed code. C # is one of several ways to compile source code into a managed code language. Managed code is packaged into an assembly, which can be an. exe or. dll (library) Form, including type information and metadata.
Managed code is represented by intermediate Language or IL. When the CLR loads an assembly, he converts IL to the host's native code, such as X86. This conversion is done through the CLR's JT (just-in-time) compiler. The Assembly retains almost all of the source language's deconstruction, which makes it easy to detect and generate code dynamically.
Tip: the. NET Reflector of Red Gate is an important tool for analyzing the contents of an assembly (you can use it as an anti-compiler).
The CLR is the host of countless runtimes. These services include memory management, program loading, and security services. The CLR is language-independent. He allows developers to use multiple languages (for example: C #, Visual Basic,. NET, Managed C + +, delp.net, Chrome. NET and J #) to develop applications. The. NET Framework only supports libraries that are basic to all Windows platforms or Web-based applications.
1.7 C # and Windows Runtime
c#5.0 also implements interoperability of the Windows Runtime (WinRT) libraries. WINRT is an extensible interface and runtime environment that allows access to libraries in an object-oriented and language-agnostic manner. Win8 with this runtime, which is an extended version of the Microsoft Component Object model or COM. (Minimum win8)
1.8 c#5.0 New Features
c#5.0 Two A large new feature is the ability to support asynchronous functions with two keywords (async and await). Async functionality supports the use of asynchronous continuations, which simplifies fast response and thread-safe client application writing. They also facilitate the writing of highly concurrent and highly efficient I/O intensive applications, without the need to bind a thread resource for each operation.
Introduction to the C # and. NET Framework