Initializing IEnumerable<string> In C#
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[]{};
IEnumerable<T>
is an interface. You need to initiate with a concrete type (that implements IEnumerable<T>
). Example:
IEnumerable<string> m_oEnum = new List<string>() { "1", "2", "3"};
As string[]
implements IEnumerable
IEnumerable<string> m_oEnum = new string[] {"1","2","3"}
IEnumerable
is just an interface and so can't be instantiated directly.
You need to create a concrete class (like a List
)
IEnumerable<string> m_oEnum = new List<string>() { "1", "2", "3" };
you can then pass this to anything expecting an IEnumerable
.