O'Reilly logo

.NET Gotchas by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Language and API Gotchas

Languages like C# and VB.NET allow you to develop object-oriented code without the complexity of syntax found in languages like C++. Nevertheless, there are features of the C# and VB.NET languages, and the .NET Framework types, that are likely to run counter to your intuitions. In particular, your experience with other languages may lead you to expect that certain features will behave in familiar ways in .NET and that the .NET languages will be consistent in how they handle common tasks. If so, you’ll be in for some surprises. For example, .NET takes a different approach to copy constructors than C++ does. The .NET XML reader needs some help to work as quickly as you might expect. And the VB.NET and C# language compilers don’t handle object initialization in the same way; nor do they spot bad enumerations at compile time, as you might expect.

In this chapter I focus on gotchas at the language and API level of the .NET platform.

GOTCHA #20 Singleton isn’t guaranteed process-wide

A static/Shared field belongs to the class and is not part of any instance. Typically, when you see a static/Shared field, you know that no matter how many instances of the class exist, there is one and only one occurrence of this field. Often a static/Shared field is used to limit the number of instances of an object—the concept of Singleton. (Refer to “Exploring the Singleton Design Pattern” and "Implementing the Singleton Pattern in C#" in the section "on the web" in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required