![]() |
![]() |
All Products | Support | Search | microsoft.com Home | |
![]() |
![]() | ||
Home | About This Site | Support | Worldwide Sites | Advanced Search | Newsletter | |
|
![]() |
![]() |
|
![]() | ||||||||
![]() An
Introduction to .NET with C# ![]() By Scott Mauvais Microsoft .NET is very, very cool. It is certainly the most important thing Microsoft has developed since COM. Microsoft .NET might be the most important thing Microsoft has developed since the original release of Windows. It has been quite a while since we developers have had something to get this excited about. Microsoft has released some exciting technology for developers recently�COM+, the WebStore, Microsoft SQL Server 2000's native XML support�but these products have been, for the most part, infrastructure hand-me-downs. .NET is about to change all that. Although Microsoft .NET will influence nearly every aspect of Microsoft's product line�in fact we are already starting to see the impact with the recent release of the .NET Enterprise Servers�it's really all about making developers more productive. It's about time. Roughly a year has passed since Microsoft announced the .NET strategy at the Forum 2000 event last May and it has generated a tremendous amount of excitement. If you ask a handful of your colleagues what .NET is, you are sure to get a variety of answers. Some people might mention aspects such as software as a service, Web Services and XML everywhere, and �xcopy� deployment. Others might mention the Common Language Runtime (CLR), managed code, and the Microsoft Intermediate Language (MSIL). Though I doubt that any two people will list all the same .NET features, one feature I bet nearly everyone will include is Microsoft's new language, C#.
In this article, I aim to provide an introduction to .NET and discuss some of the ways that it will make you rethink (in a good way) how you approach software development. Because Microsoft built C# from the ground up to be a first-class .NET language, the best place to start is with a programmer's overview of .NET. From there I will move on to a brief discussion of the C# language itself; I'll conclude with a discussion of the effect that a completely object-oriented .NET language will have on the way we approach complex projects. The .NET Vision Servers Building Block Services Devices Development Tools Moving from .NET Vision to .NET
Reality Common Language Runtime
Many people think that the CRL is a virtual machine similar to the Java VM. Nothing could be further from the truth. When you compile a .NET language, the compiler initially emits Microsoft Intermediate Language (MSIL). MSIL, however, is never executed or interpreted in any way. Rather, it is translated directly into native code�either explicitly when you install the application or by one of the .NET JITs when the application first runs. .NET Framework Libraries Although not technically part of the Framework Libraries, the Common Language Specification (CLS) defines the requirements that a language's compiler must follow for the CLR to run its applications. Because the CLS serves to ensure interoperability across .NET languages, it only deals with the externally visible aspects of a language and is mainly concerned with keeping one language from breaking another. Therefore, the CLS sets forth a rather limited set of requirements. To be CLS-compliant, a language must expose only CLS-compliant types (those defined by the .NET CTS) and must be able to use any CLS-compliant type exposed by another .NET language. As a result, nothing requires all the languages and their compilers to support every feature of the CLS. Therefore, even though all your .NET applications will work together regardless of which languages you write them in, some languages might implement more of the .BCL than others. Microsoft will include four languages with .NET: C#, Visual Basic.NET, JScript, and Visual C++ with managed extension. Other companies are working with the CLS and producing .NET versions of popular languages such as COBOL, Perl, Python, and Eiffel. In fact, because the CLS is a public specification, nothing prevents you (or anyone else) from designing your own language. Because C# is Microsoft's flagship .NET language, it does implement nearly every feature supported by the BCL. So while the .NET framework insures that all .NET languages are equal, C# is probably a bit more equal than others. C# Okay, so C# will make the OOP purists happy. What about the folks who just want to be productive? First off, the primary C# design goal was to provide the power and flexibility of C++ while maintaining the ease of use and RAD functionality of VB. Second, because C# syntax shares a common heritage with C and C++, picking it up will be easy for anyone with experience with any other C-like language. Even if you have not worked with C, you will find C# easy to pick up because of its elegance and consistency. Better yet, read Tom Archer's Inside C#. His lucid writing and liberal use of clear examples will quickly bring you up to speed. Once you're familiar with C#, you will see that it will change your approach to software development. Strictly from a code-warrior level, .NET is all about language interoperability. I can write a class in C#, subclass it in VB, and finally use it from a Web page written in ASP.NET that uses the Adaptive User Interface (AUI) to output HTML to a WAP-enabled phone. And I won't lose any fidelity along the way. As a result of C#, people will start mixing and matching languages within a given project and probably even within a single tier of an application. Why? Simply because this is what's possible when you're no longer locked into using a single language. For example, let's say that I need to process some Web logs to perform statistical analysis based on the length of a user's session. The first thing I might want to do is remove all the extraneous noise from the logs, such as requests for images and style sheets. To do this, I would probably use Perl because of its superior string handling. However, when it comes time for the heavy lifting of sessionizing the logs and doing my statistical work, I might choose something like C#. When you start moving in this direction, you will find that you need to pay much more attention to the design of your base classes. These days, we can get away with less-than-robust class structures because code re-use in the real world is limited by language incompatibilities and platform differences. In a .NET world, all those problems go away, and you will come to rely on your base classes more than ever. As you prepare for C#, I strongly recommend that you revisit some of the standard OOP concepts such as encapsulation, abstraction, polymorphism, and most important, inheritance. I know what you're thinking�that stuff is old hat; you think you have it down pat. After years of bad habits fostered by developing in �object-compromised� environments, your OOP skills are probably not what they used to be. I know mine weren't. Anticipating this, Archer's first chapter, �The Fundamentals of Object-Oriented Programming,� is the perfect refresher to make sure you still have those good design skills. Conclusion Microsoft Press provides in-depth documentation for these and all the other issues related to developing for .NET. For a complete list of .NET titles from Microsoft Press, see the Inside Information on Microsoft .NET page. The best place to start is with Tom Archer's new book, Inside C# is the authoritative guide to programming with C#�the language on which the .Net Platform is built. Microsoft C# Language Specifications contains the complete specification for C#. For detailed information on all Microsoft Press Windows 2000 titles for developers, visit the Windows 2000 for Developers page. For a complete list of all the developer titles, see the Developer Tools section. For more information on Microsoft Visual Studio.NET, see the Visual Studio Next Generation Home Page. To get started right away, you can download the Microsoft .NET Framework SDK Beta 1. One great way to learn more about the .NET SDK is to review the slides from last summer's Microsoft Professional Developers Conference. For peer support, you can access several .NET newsgroups, including one devoted to C#. Microsoft C# Language Specifications contains the complete specification for C#.Table of Contents, Sample Chapter | ||||||||||||
|