A Taste of Language

It is difficult to separate Visual Studio from the languages it supports, even though the languages and the development environment around them are not the same things. But because Microsoft has a high degree of control over both, it seems that the two concepts can blur together. Certain IDE features might operate on one language but not on others.

After a purist but probably misguided effort to make C# and Visual Basic functionally equivalent languages in .NET (although implemented differently in some cases), Microsoft has seemingly conceded that providing functionally different languages for different constituents and purposes is valid, and continues to define valuable but separate features for its two managed languages. (I did not look at J#, which likely exists only as a carrot to wayward Java developers.)

New features for C# as a language include generics, iterators, partial classes, and anonymous methods. Generics get a lot of attention, and with good reason—they enable you to implement algorithms without regard to the data type that might use them (see Figure A). You write the algorithm with tags indicating data, and the Framework figures out the correct data types at run time. It sounds slow, but remember that the code is already JIT-compiled. The type is determined at that time, then runs at normal object code speeds. Visual Basic also implements a form of generics. Generics are subclassed from the System.Collections.Generic namespace.

Almost all programs do iteration of some type, which offers the potential for both development and runtime efficiencies. C# uses a foreach, do, for, or while instruction to enumerate through any list of collections. However, setting up those collections used to be a bit of a chore. New iterator keywords alleviate the work of writing code and make it easier for developers to create easily enumerable collections.

Anonymous methods provide the ability to pass code segments as parameters in method calls. You can use these methods in any construct where you might normally make a call to a delegate. Passing a code segment can save the effort of writing an additional method along with the delegate.

These are the sorts of features that are turning C# into the new "software engineering" language, with a focus on building large and complex software systems. C# lets you not only do sophisticated things with code, but also keep better track of and manage that code.