x.Key); -6ren">
gpt4 book ai didi

c# - "Interface name is not valid at this point"

转载 作者:行者123 更新时间:2023-11-30 19:10:29 27 4
gpt4 key购买 nike

public IEnumerable<decimal> SomeKeys
{
get
{
return dbContext.SomeTable.Select(x=>x.Key);
}
}

public IEnumerable<decimal> SomeOtherKeys
{
get
{
var ret = IEnumerable<decimal>(); // interface name is not
// valid as this point
// do stuff with ret
return ret;
}
}

使用我当前的代码,我得到了上面的异常。

我必须返回 List<decimal> 吗? ?或者我应该如何返回 IEnumerableIQueriable数据类型?

最佳答案

这是 var ret = IEnumerable<decimal>();只是无效 C#代码,即。

你可能想做这样的事情:

var ret = new List<decimal>();

记住 List ,引用文档,源自 IEnumerable<T>也是。

public class List<T> : IList<T>, ICollection<T>, 
IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>,
IEnumerable

这样的代码

public IEnumerable<decimal> SomeOtherKeys
{
get
{
var ret = new List<decimal>();
// do stuff with ret
return ret;
}
}

完全有效。

关于c# - "Interface name is not valid at this point",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com