The Future of Managed Languages: C# and Visual Basic
Dynamically Typed Objects
// Method chosen at compile time double x = 1.75; double y = Math.Abs(x); // Method double Abs(double x) chosen at run-time dynamic x = 1.75; dynamic y = Math.Abs(x); // Method int Abs(int x) chosen at run-time dynamic x = 2; dynamic y = Math.Abs(x);
Optional and Named Parameters
Optional and named parameters are items being introducedin to C# that gives it more parity with Visual Basic.Optional and named parameters have existed in Visual Basicfor as long as I can remember and will now be in C# aswell.
// Optional parameters have default values public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024); // Leaving off parameters in the call OpenTextFile("foo.txt", Encoding.UTF8); // Named parameters can appear in any order OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false);
Improved COM Interoperability
The object binders introduced with the DLR along with theintroduction of optional and named parameters provides abetter COM interoperability experience overall.
// Original code object fileName = "Test.docx"; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); // Replacement code now possible doc.SaveAs("Test.docx");
Future Directions for Visual Basic
Much of the language innovations currently planned for VB10 focus around the aforementioned parity. The list containsbut is not limited to the following:
- Generate from use - type an object name and allow the IDE to generate a stub object or method.
- Auto-implemented properties - create a public property that is not backed by a full accessor method or field and the compiler will generate one.
- List initializers - ability to create an initialize a list all within a single statement the same as what C# supports.
- Implicit line continuation - do not have to use the annoying "_" in order to continue a line to the next line!
- Parallel extensions - extensions added to support parallel programming.
- No primary interop assembly - ability to embed referenced types directly within an assembly.
You have learned about a shared goal between C# andVisual Basic as well as some of the industry trends that areinfluencing the next release of the two languages. We lookedspecifically at some of the items planned for bothlanguages. I hope that it provided you high-level insight asto what is coming.
The topic of the next column is likely to be a deeperdive in to one of the topics on the next release of the .NETFramework. If you have something in particular that youwould like to see explained here you could reach me at