Reputation: 788
I have the following code.
public IEnumerable<int> BillLevel { get; set; }
I want to add values like this
BillLevel = [1, 2, 3, 4, 5],
What is the right syntax to assign an array of int to this list?
Upvotes: 0
Views: 541
Reputation: 1
You must to pass the reference of a class which implement IEnumerable Interface. Such as List Class implement this interface so you can pass the instance of List of int into this
public IEnumerable<int> BillLevel { get; set; }
BillLevel = new List<int>(){1,2,3,4,5};
Upvotes: 0
Reputation: 2323
This intilalizes the BillLevel property with an array of intergers.
BillLevel = new[] {1, 2, 3, 4};
Upvotes: 0
Reputation: 15005
IEnumerable
is an Interface so first you need to declare it with a class which implements IEnumerable
like List
and then simply add to list.
public IEnumerable<int> BillLevel { get; set; }
BillLevel = new List<int>();
BillLevel.AddRange(new int[]{1, 2, 3, 4, 5});
Or you can Add the numbers in declaration
BillLevel = new List<int>(){1, 2, 3, 4, 5};
Upvotes: 1