Initializing IEnumerable<string> In C#

markzzz picture markzzz · Jul 4, 2011 · Viewed 194k times · Source

I have this object :

IEnumerable<string> m_oEnum = null;

and I'd like to initialize it. Tried with

IEnumerable<string> m_oEnum = new IEnumerable<string>() { "1", "2", "3"};

but it say "IEnumerable doesnt contain a method for add string. Any idea? Thanks

Answer

sehe picture sehe · Jul 4, 2011

Ok, adding to the answers stated you might be also looking for

IEnumerable<string> m_oEnum = Enumerable.Empty<string>();

or

IEnumerable<string> m_oEnum = new string[]{};