Want generics? How about a three-valued Boolean class that can be true, false, and null? Those are all new computer language features coming as part of Microsoft's Visual Studio 2005.
Programming languages evolve. That's true, whether you're talking about Ada or Algol 68, COBOL or C#, or FORTRAN or Forth. New language features appear from time to time to address issues that developers face using the language in real-world applications. They also appear in order to accommodate new paradigms or to improve compatibility with run-time platforms.
To accommodate the latest version of its IDE, Visual Studio 2005, Microsoft has introduced changes into Visual Basic and C#. Those changes fall into three areas: changes to the language itself; changes to the compiler and how it converts source code into managed executables, and changes to the IDE to better support coding in that language.
Our focus here: What's new in the Visual Basic and C# languages for 2005. You should find both some new features and some old friends.
Changes to Visual Basic
VB has gone through a lot of evolution during the past years. The biggest jolt came when moving from Visual Basic 6 to VB.NET; Microsoft had to do a lot of things to make VB work within the .NET Framework and the Common Language Runtime. Unfortunately, a lot of developers didn't give the changes and new features a fair chance, but instead, got angry about changes that they thought were gratuitous. Since that initial VB.NET release several years ago, Microsoft has continued tuning and tweaking the language; if you and your team walked away from VB.NET during that transition, perhaps it's time to take another look at Visual Basic.
One of the biggest changes to VB 2005 is that it conforms to Microsoft's new Common Language Specification. The CLS defines rules that improve interoperability between different .NET languages, specifically by requiring objects to expose only features that are common to all of the managed languages that they must interoperate with. That way, an object will work the same way in VB 2005, C#, C++, or any other .NET language that runs under the Common Language Runtime. The new compiler generates warnings if your code isn't compliant with the CLS specifications.
Some examples of changes to the language to support the CLS include: All updated Microsoft languages, including VB 2005, now support 11 different CLS-compliant primitive data types: Byte, Int16, Int32, Int64, Single, Double, Boolean, Char, Decimal, IntPtr and String. Except objects that are thrown must be of type System.Exception or inherit from System.Exception. The only calling convention supported by the CLS is the standard managed calling conventionvariable length argument lists are not allowed. For more cross-language interoperability, click here.
VB Beyond CLS
However, there's more new to VB 2005 than CLS compatibility, and here are some of the most important changes:
Visual Basic 2005 now supports generics, which are programming elements that tailor their operations to the data types that you specify when you decline the element. Generics are an often-requested feature for the .NET languages; they've been added to C# also. To learn more about using generic types in VB 2005, see http://msdn2.microsoft.com/library/w256ka79(en-us,vs.80).aspx.
The language now has a Continue statementsomething that's been missing since the Visual Basic 6 era. The Continue statement provides a way to skip immediately to the next iteration of a Do, For, or While loop. For more on that, see http://msdn2.microsoft.com/library/801hyx6f(en-us,vs.80).aspx.
VB 2005 also introduces an IsNot operator, which makes object comparison operations that require both the Not and Is operators less clumsy to read. (Think of it as being like the "not equal" operation for numeric logic.) Before, if you wanted to compare to see if two objects were different, you'd have to write it as If Not A Is B Then <action>. Now, you can write that logic more intuitively as If A IsNot B Then <action>.
To help improve resource management, VB 2005 lets you define a Using block, which lets you define which system resources you'll use temporarily. When you exit the Using block using the End statement, those resources are released. For more, see http://msdn2.microsoft.com/library/htd05whh(en-us,vs.80).aspx.
Another change: VB 2005 now supports both signed and unsigned integer data types. Previously, VB.NET and VB 2005 only supported signed integers. There are three new types: The 16-bit UShort (holds from 0 through 65,535) corresponds to the System.UInt16 structure in the .NET Framework; The 32-bit UInteger (holds from 0 through 4,294,967,295) is the System.UInt32; And the 64-bit ULong (holds from 0 through 18,446,744,073,709,551,615) matches up with System.UInt64. Note that unsigned integers aren't CLS compliantthat is, not all .NET Common Language Runtime languages can use them.
Now that we've looked at some of the biggest changes to Visual Basic, let's drop in on C# 2.0the updated version of the language that appears with Visual Studio 2005.
What's New with C# Two
Some of the changes that we discussed above for Visual Basic 2005 are also new to C# 2.0. For example, C# also adds support for generics (for more on that, see http://msdn2.microsoft.com/library/512aeb7t(en-us,vs.80).aspx). C# was already compliant with the Common Language Specification, so nothing new there.
C# 2.0 adds iterators, which are methods that let you use the foreach statement over an entire class. An iterator code lets you specify how return values will be generated when each pass through the foreach loop accesses each element of the collection. Putting it another way, the iterator makes it easier to implement IEnumerable or IEnumerator methods by automatically keeping track of the current element in the collection. It takes care of the plumbing, in other words, which not only keeps the source code simpler, but also reduces the possibility of coding errors in loops.
You can now define a partial class in C#. A partial class is one in which the class, struct, or interface definition is split between multiple source files. The biggest benefit is that it makes it easy to add code to an automatically generated class without having to modify the auto-generated source code. It also lets you modify classes that someone else wrote, or that come as part of a packaged component, without modifying the source code. You define the partial class simply by using the partial keyword modifier in the class definitionsee http://msdn2.microsoft.com/library/wa80x488(en-us,vs.80).aspx.
Another new language feature is the static class, which is for classes (and class members) that may be accessed by an object without creating an instance of the class. A static class is useful for accessing external databases, for example, without the overhead of instantiating the class. Learn more at http://msdn2.microsoft.com/library/79b3xss3(en-us,vs.80).aspx.
One final change we'll discuss: C# now allows the use of nullable typesthat is, types that allow you to not only define the usual integers, floats, Booleans, or strings, but also "null". The null value can be used to indicate data that's undefined. For example, a Boolean field typically stores the values "true" or "false"if you define it as nullable, its values can be true, false, or "neither true nor false." Perhaps they should call that the Shroedinger's Cat type: It's neither dead or nor alive.
There's More to Learn
There are other changes coming to the Visual Basic 2005 and C# 2.0 languages, and as mentioned above, Visual Studio 2005 also presents new compiler behaviors and IDE features to accommodate the languages. One source of information is on MSDNsee http://msdn2.microsoft.com/library/we86c8x2(en-us,vs.80).aspx to catch up on Visual Basic 2005 and http://msdn2.microsoft.com/library/t27ahy37(en-us,vs.80).aspx to find out what's new in Visual C# 2005 and the C# 2.0 language.
However, if you're an ISV, another way to learn is to attend the ISV Touchdown Web Seminars taking place in October. Those seminars will demonstrate and teach not only the language enhancements, but also the compiler and IDE changes for Visual Studio 2005and include a lot of code examples and details.