0

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?

2
  • How about using AddRange Commented Jul 1, 2016 at 10:17
  • How about using an enum? Commented Jul 1, 2016 at 10:23

3 Answers 3

1

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};
Sign up to request clarification or add additional context in comments.

1 Comment

Did the trick thank you! Now I want a value to display it on the view. I use angularJS ng-model="//get selected value in combobox" ng-options="//billevel"
0

This intilalizes the BillLevel property with an array of intergers.

BillLevel = new[] {1, 2, 3, 4}; 

Comments

0

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};

1 Comment

Thanks man ! Is there a way to set BillLevel on index 3 for example ? (default value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.