Yanıtlar:
Tamam, ayrıca arıyor olabileceğinizi belirtilen cevaplara ekleyerek
IEnumerable<string> m_oEnum = Enumerable.Empty<string>();
veya
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();
İstenen IEnumerable'ı şu şekilde döndürecek statik bir yöntem oluşturabilirsiniz:
public static IEnumerable<T> CreateEnumerable<T>(params T[] values) =>
values;
//And then use it
IEnumerable<string> myStrings = CreateEnumerable("first item", "second item");//etc..
Alternatif olarak şunları yapın:
IEnumerable<string> myStrings = new []{ "first item", "second item"};
IEnumerable bir arabirimdir, bir arabirim örneğinin nasıl oluşturulacağını aramak yerine arabirimle eşleşen bir uygulama oluşturun: bir liste veya bir dizi oluşturun.
IEnumerable<string> myStrings = new [] { "first item", "second item" };
IEnumerable<string> myStrings = new List<string> { "first item", "second item" };