If you hadn’t heard already last week at BUILD we announced the PUBLIC release of a Preview of the next version of the Visual Basic language and code editing experience powered by “Roslyn”. You can download this preview and install it on top of Visual Studio 2013 today!
I’m excited to let you know that included in this is a preview of a new language feature we’re considering that let’s you Select Case on the type of an object like this:
Select Case objCase t As TextBox
Case b As Button
You can read about it more here: http://www.codeplex.com/Download?ProjectName=roslyn&DownloadId=824695
Download the End User Preview @ http://msdn.microsoft.com/en-US/vstudio/roslyn
I encourage you all to download it, try it out, and send us your feedback.
Anthony D. Green, Program Manager, Visual Basic & C# Languages TeamXDotNet commented
Add linq/lambda as well
Select case From c as customer in myList(of Customer) where c.contains("Marsha").First
The possibilities are limitless especially you allow "Case" to have some logic.
Select case From c as customer in myList(of object) select c
Case is typeOf Dictionary(of string,string)
Case is typeOf ListOf(String)
Case is typeOf Dictionary(of Date, String)
Great suggestion. As you’ve noted in all of your suggestions there’s a lot more potential with the Select Case statement that we don’t yet support. Reference equality comparisons (Is/IsNot) and the Like operator are great examples as is type-checking. We’re actively thinking about improving the Select Case statement for these scenarios.
Your suggestion is actually the most likely syntax we would use if we were to implement this feature and it seems more like a bug that it doesn’t just work. That said is the Like operator still useful to you compared to say RegEx – which is more powerful?
-Anthony D. Green, Program Manager, Visual Basic & C# Languages TeamXDotNet commented
Add linq/lambda too
Select Case = From c as customer in myList(of Customer) where....