31. March 2011 12:57
Okay, something very cool in VB.Net as of VS2010 is that you can use literals for assignments to generic collections...
'List from Literal
Dim myList As New List(Of Integer)() From {1,2,3,4,5}
'Dictionary from Literal
Dim myDic As New Dictionary(Of String, Integer)() From {
{"key1", 1},
{"key2", 2}
}
Then when trying to load with Tuple's as the value, I ran into a snag, since it didn't understand the conversion of the tuple literal values. I found that by creating the needed extension methods into this module that I could do what I wanted to accomplish.
Dim myQueue= New Queue(Of Tuple(Of Integer, Integer)) From {
{19, 63},
{20, 63}
}
As you can see, it really isn't so difficult to use, but can be really useful when using paired values in a given collection. Generic classes such as Tuple, and Generic collections can help a lot in data iteration.
TupleExtensionsForGenericCollectionsModule.vb.txt (4.45 kb)