Question

please I need to create a C# array with following exact format:

  var sampledata =  {
                      {Day: "Sunday", Quantity: 15},
                      {Day: "Monday", Quantity: 20},
                      {Day: "Tuesday", Quantity: 80}
                    }

can we create something like the above in C#. if yes, please how? thanks...

Was it helpful?

Solution

var sampledata = new[] {
    new { Day = "Sunday",  Quantity = 15 },
    new { Day = "Monday",  Quantity = 20 },
    new { Day = "Tuesday", Quantity = 80 }
};

try a Array or a List of anonymous Types (http://msdn.microsoft.com/en-US/en-en/library/bb397696.aspx)

OTHER TIPS

Use object and array together?

class Order
{
    public String Day;
    public int    Quantity;
}

Order[] orderArray = new Order[3];
orderArray[0].Date = "Sunday";
orderArray[0].Quantity = 15;
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top