.NET and C# introduction In order to understand the significance of .NET, it is useful to remind ourselves of the nature of many of the Windows technologies that have appeared in the past ten years or so. Although they may look quite different on the surface, all of the Windows operating systems from Windows 3.1 (introduced in 1992) through Windows Server 2003 have the same familiar Windows API at their core. As we’ve progressed through new versions of Windows, huge numbers of new functions have been added to the API, but this has been a process of evolving and extending the API rather than replacing it.
While backward compatibility has been a crucial feature of Windows technologies and one of the strengths of the Windows platform, it does have a big disadvantage. Every time some technology evolves and adds new features, it ends up a bit more complicated than it was before.49282
This fresh start is what C# and .NET are all about. Roughly speaking, .NET is a new framework—a new API—for programming on the Windows platform. Along with the .NET Framework, C# is a new lan- guage that has been designed from scratch to work with .NET, as well as to take advantage of all the progress in developer environments and in our understanding of object-oriented programming princi- ples that have taken place over the past 20 years.
It’s in this context that Microsoft has decided to give developers an alternative—a language designed specifically for .NET, and designed with a clean slate. Visual C# .NET is the result. Officially, Microsoft describes C# as a “simple, modern, object-oriented, and type-safe programming language derived from C and C++.” Most independent observers would probably change that to “derived from C, C++, and Java.” Such descriptions are technically accurate but do little to convey the beauty or elegance of the lan- guage. Syntactically, C# is very similar to both C++ and Java, to such an extent that many keywords are the same, and C# also shares the same block structure with braces ({}) to mark blocks of code, and semi- colons to separate statements. The first impression of a piece of C# code is that it looks quite like C++ or Java code. Behind that initial similarity, however, C# is a lot easier to learn than C++, and of comparable difficulty to Java. Its design is more in tune with modern developer tools than both of those other lan- guages, and it has been designed to give us, simultaneously, 论文网the ease of use of Visual Basic, and the high- performance, low-level memory access of C++ if required. Some of the features of C# are:
(1)Full support for classes and object-oriented programming, including both interface and imple- mentation inheritance, virtual functions, and operator overloading.
(2)A consistent and well-defined set of basic types.
(3)Built-in support for automatic generation of XML documentation.
(4)Automatic cleanup of dynamically allocated memory.
(5)The facility to mark classes or methods with user-defined attributes. This can be useful for doc- umentation and can have some effects on compilation (for example, marking methods to be compiled only in debug builds).
(6)Full access to the .NET base class library, as well as easy access to the Windows API (if you really need it, which won’t be all that often).
(7)Pointers and direct memory access are available if required, but the language has been designed in such a way that you can work without them in almost all cases.
(8)Support for properties and events in the style of Visual Basic.
(9)Just by changing the compiler options, you can compile either to an executable or to a library of .NET components that can be called up by other code in the same way as ActiveX controls(COM components).
(10)C# can be used to write ASP.NET dynamic Web pages and XML Web services.
Most of the above statements, it should be pointed out, do also apply to Visual Basic .NET and Managed C++. The fact that C# is designed from the start to work with .NET, however, means that its support for the features of .NET is both more complete, and offered within the context of a more suitable syntax than for those other languages. While the C# language itself is very similar to Java, there are some improve- ments: in particular, Java is not designed to work with the .NET environment.