Search code examples
c#arrayscollectionsgeneric-collections

c# Array or Collection


How would you approach this? I have a list of data that has two things that need to be stored price and item, is there anyway to store this in an array without knowing the total number of rows that I will have? Or should I use a collection can those be multidimensional?

Thanks


Solution

  • Yes - I'd recommend you look into a generic list. Using this you can model your data and store as many items as you like.

    For example

      public class PricedItem
        {
            public decimal Price { get; set; }
            public object Item { get; set; }
        }
    

    These could then be stored/retrieved in a List<PricedItem> - or as 'list of priced items'.

    Hope that helps