I am taking an MVC tutorial that is teaching about ViewBags in ASP.NET. It never goes into what a ViewBag really is, it just shows you when and how to use it. I ran into the code below, and it seems to treat the ViewBag as an array in this particular instance, when I didn't think it is an array.
@for(int i = 0; i <= ViewBag.Items; i++)
{
<li>ViewBag.Items[i]</li>
}
What is ViewBag exactly? A data dictionary? A collection? An array? Seems like it is a dictionary from what I can research but I can't seem to find a clear answer, as the resources I found just tell you how and when to use it. I looked here, but the info was very sparse and not completely clear to me.
Please note, my C# skills are not completely comprehensive yet although I have a decent general understanding. How can this be treated as an array?
Also, why is it i <= ViewBag.Items in the for loop instead of ViewBag.Items.Count? No explanation from instructor, he just uses it and never explains this discrepancy. Thank you for any assistance you can provide to clear my misunderstanding up.