views:

243

answers:

1

Hi,

is there in VB.NET something like this in php?:

$var["a1"]['name']="Mike";
$var["a1"]['nick']="MMM";

I tried hashtables, dictionary, lists and arrays in .net, all I could get is a simple key=>value array Is there a simple solution if not, is there a class or something for this?

Thanks.

+2  A: 

You could always create a structure and place that into a dictionary.

Something like this:

Private Structure Person
  Public Name as String
  Public Nick as String
End Structure

Then your dictionary like this:

  Dim myDictionary as Collections.Generic.Dictionary(Of String, Person)
Sonny Boy
Why not a class?
Meta-Knight
thanks man! you ended my 10 hours of craziness ;)
qxxx
@Meta Structures are a lot more light-weight so if you don't need all the OO stuff a Class provides you're usually better off with a Structure.
Sonny Boy
As I understand it, structures are only light-weight if they hold only value types (other structures). This is because value types can be stored on the stack, and avoid the small performance hit of looking up a reference to an object on the heap. String is a class, stored on the heap, so a structure holding two strings is no more light-weight than a class holding two strings.
Joel Mueller
@Joel Yes. That is the case. However classes also support inheritence and polymorphism whereas structures do not. That was the overhead to which I was referring earlier. Also, keep in mind, if you're performing a large number of operations then a Structure will still be preferable as it sits on the stack (even if the strings/objects within it are still on the heap).
Sonny Boy