Multiple Generics restrictions in VB.NET
Posted by Fernando Felman on July 17, 2007
Did you know that VB.NET accept curly brackets ({ })? Neither did I, but it does for the special case of multiple restrictions describing a Generics type.
I needed to code a web service factory, and I used Generics to do so. In C#, the code would look like this:
The Generic type T has multiple restrictions: it derives from the base web service proxy and it implements a default constructor. Easy. But the project using this will be a VB.NET, and I’d prefer to have this factory in the same language. So, after some digging, here’s the same factory implemented in VB.NET:
Seams to me that the multiple restrictions notation in VB is very much like an in-line array initiation in C#. I think some C# developer suggested this syntax – it’s just so not VB like…



Avner Kashtan said
Not VB like, except for the fact that it’s the same syntax that VB.NET uses for array initializations. Guess the C# guys already got to them…