Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert value in a IEnumerable<int>?

Tags:

c#

I have this :

IEnumerable<int> intYear = Enumerable.Empty<int>();

how can I insert some values? I Don't see any intYear.Add() method.

Like 2010, 2011, and so on...

like image 478
markzzz Avatar asked Dec 05 '11 11:12

markzzz


Video Answer


1 Answers

You should use an IList<int> instead of IEnumerable<int> for that:

IList<int> intYear = new List<int>();
intYear.Add(2011);
// and so on

IList<T> implements IEnumerable<T> so you can pass it to any method taking an IEnumerable<T> as argument.

like image 56
Fredrik Mörk Avatar answered Oct 20 '22 02:10

Fredrik Mörk