Who This Book Is For


This book is intended for the .NET programmer in the trenches. This includes both C# and VB.NET programmers. I assume that you are fairly familiar with .NET programming using either C# or VB.NET. I also assume that you are acquainted with the terms and vocabulary used by Microsoft in describing the .NET platform. In addition to programmers, project leads and senior programmers may find this book helpful in setting standards and guidelines for their development teams.

How This Book Is Organized

.NET Gotchas is organized into eight chapters, each focusing on a different area of interest in .NET. Each item has a name, title, and includes code examples, discussions, and guidelines "In a Nutshell." The items are grouped into the area that I find to be the most appropriate. At the end of each item, related gotchas are referenced for your convenience. The examples are presented in both C# and VB.NET (clearly marked so you can easily identify these without having to examine the code). The code is labeled with the directory where you can find the example when you download the source code from the online resource. The output shown is from the C# code, unless the output from C# differs from the VB.NET output, as is the case in a few gotchas. Where they are different, both the C# output and the VB.NET output are shown and discussed.

CLR/FRAMEWORK GOTCHAS

The Common Language Runtime (CLR) and the .NET framework provide programmers with a high level of abstraction and ease of use. They pave the way for writing code, more or less consistently, in any of the different languages supported by .NET. However, there are aspects of both that are confusing, misleading, or prone to misuse. Also, certain features and choices can impact the behavior or performance of your code. In this chapter I focus on those issues.

VISUAL STUDIO AND COMPILER GOTCHAS

The translation of your source code into Microsoft Intermediate Language (MSIL) is the job of the C# and VB.NET compilers. However, there are things that are "lost in the translation." While .NET allows you to develop code in the language of your choice, there are things that certain compilers do not look out for. In this chapter I discuss issues that will surprise you in the area of program compilation and the use of Visual Studio for development. Also, you will learn about the inconsistencies between the different language compilers.

LANGUAGE AND API GOTCHAS

.NET languages support object-oriented development, while avoiding some of the perils of powerful (but treacherous) languages like C++. Unfortunately, the .NET languages have introduced features that lead to poor object-oriented practices. Furthermore, while your experience with other languages may lead you to expect that certain features will behave in familiar ways, with .NET you will learn that this is not always so.

LANGUAGE INTEROPERABILITY GOTCHAS

The MSIL is the core language of .NET. Code written in different .NET supported languages is translated into MSIL. This provides you the ability to interoperate with code written in different languages in a powerful and useful way. You can use the .NET language of your choicethe one that you are most comfortable with. Your team can mix different languages in developing your system. While all this sounds terrific, are there any issues that will get in the way? In this chapter you will learn the issues that can affect your efforts to interoperate between .NET languages.

GARBAGE COLLECTION GOTCHAS

.NET provides automatic garbage collection. There is nothing we have to do or worry about in terms of object lifetime. Just sit back and relax, we're told. Does that sound too good to be true? While garbage collection is automatic, it may not do its work on the schedule you might prefer. As long as you are dealing with only managed resources this is not a problem. However, the reality is that you must often contend with unmanaged resources, which the CLR won't know how or when to clean up. In this chapter you will learn about the various issues related to garbage collection and how to write code that works correctly.

INHERITANCE AND POLYMORPHISM GOTCHAS

Inheritance and polymorphism are core features in object-oriented programming. Compared to other object-oriented languages, .NET has introduced keywords and facilities that are either new or different. While these were provided with good intent, some are misleading. Not understanding these features can affect the extensibility of your code and make it harder to derive from your classes. In this chapter you will learn what to avoid and how to use other features related to inheritance and polymorphism.

MULTITHREADING GOTCHAS

Creating a thread is easy; managing it is another story. How do you take care of thread safety? Should you create your own thread or use a thread from the thread pool? How are exceptions handled in multithreaded applications? What other issues do you need to think about when creating a .NET multithreaded application? This chapter will help you understand the fundamental issues that can make a difference between the success or failure of a multithreaded application.

COM-INTEROP AND ENTERPRISE SERVICES GOTCHAS

If you have to work with legacy code, .NET and COM interoperability is of interest to you. The COM-Interop facilities provided in .NET make this task almost seamless, and putting it to use appears pretty simple. However, to use COM-Interop correctly, you need some forethought and planning. If you think using a COM component from .NET is simple, think again. You need to fully understand issues related to the apartment of the thread, the resource cleanup, and the layering of your application. How do you expose your .NET components for COM interoperability? Should you just turn on the Visual Studio settings to register the type library? What do you need to do to make this effective? In this chapter you will learn how to effectively interoperate between .NET and COM.



    .NET Gotachas
    .NET Gotachas
    ISBN: N/A
    EAN: N/A
    Year: 2005
    Pages: 126

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net