Reputation: 977
I have defined a new class type called Hotspot
. I need 2 dynamic array of Hotspot (I used List) and a third one that allow me to "switch" between them. Here my code:
List<Hotspot> items = new List<Hotspot>();
List<Hotspot> locations = new List<Hotspot>();
Hotspot[][] arrays = new Hotspot[][]{items, locations};
but arrays
doesn't work. I just need it so I can easily access to items/locations
array.
In F# I did it in this way:
let mutable items = new ResizeArray<Hotspot>()
let mutable locations = new ResizeArray<Hotspot>()
let arrays = [|items; locations|]
but I can't do the same thing in C#. Some help?
Upvotes: 3
Views: 352
Reputation: 134811
items
and locations
are declared (and instantiated) as lists. Lists are not arrays and you're trying to assign them as arrays. Convert them to arrays or don't use arrays at all but a list instead.
Hotspot[][] arrays = new Hotspot[][]{ items.ToArray(), locations.ToArray() };
//or
List<Hotspot>[] lists = new[] { items, locations };
p.s., The F# ResizeArray<T>
is essentially an alias to the .NET List<T>
. So in effect, the arrays
variable in your F# example is equivalent to lists
in my example above, you created an array of lists.
Upvotes: 3
Reputation: 14086
List<Hotspot>[] arrays = new List<Hotspot>[]{items, locations};
Upvotes: 4