I need to pass a list of Days (number and name) to an view!
Whats the best way to do this?
I was thinking of creating a generic collection, but not sure how? or an array?
I need to pass a list of Days (number and name) to an view!
Whats the best way to do this?
I was thinking of creating a generic collection, but not sure how? or an array?
For something like this you can use a dictionary... simple key/value pairs
Dim d as New Dictionary(Of Integer, String)
d.Add(0,"string2")
' etc
If I only had those 2 options, I'd use an Array.
Because an array is immutable. You can't accidentally "add" or "removes" something which is what the view should be. It's kind of a defensive programming.
And you can still use foreach
just fine.... so why goes Collection? no need at all.
You really ought to use an IEnumerable<T>
. Add a List<T>
to the ViewData and then cast it as an IEnumerable<T>
on the other side.
Dictionary<string, int> days = new Dictionary<string, int>();
days.Add("Sunday", 1);
...