Odpowiedzi:
Ok, dodając do podanych odpowiedzi, których możesz również szukać
IEnumerable<string> m_oEnum = Enumerable.Empty<string>();
lub
IEnumerable<string> m_oEnum = new string[]{};
public static IEnumerable<string> GetData()
{
yield return "1";
yield return "2";
yield return "3";
}
IEnumerable<string> m_oEnum = GetData();
Możesz utworzyć statyczną metodę, która zwróci żądane IEnumerable w następujący sposób:
public static IEnumerable<T> CreateEnumerable<T>(params T[] values) =>
values;
//And then use it
IEnumerable<string> myStrings = CreateEnumerable("first item", "second item");//etc..
Alternatywnie po prostu zrób:
IEnumerable<string> myStrings = new []{ "first item", "second item"};
IEnumerable to interfejs, zamiast szukać sposobu tworzenia instancji interfejsu, utwórz implementację pasującą do interfejsu: utwórz listę lub tablicę.
IEnumerable<string> myStrings = new [] { "first item", "second item" };
IEnumerable<string> myStrings = new List<string> { "first item", "second item" };