无法将类型system.collections.generic.IEnumerable <string>隐式转换为string []

Dha*_*eja 2 .net c# xamarin

试图解决并解决以下错误

public String[] Any()
{                            
    var lastSixMonths = Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6)).Select(date => date.ToString("MM/yyyy"));

    return lastSixMonths;
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*nny 5

由于lastSixMonths是,IEnumerable<string>并且您期望使用数组,请尝试以下操作:

return lastSixMonths.ToArray();
Run Code Online (Sandbox Code Playgroud)

我还创建了.NET Fiddle,以展示如何打印.NETstring[]