如果我实例化我的子类List<string>,那么我可以使用Linq的Select方法.
using System.Linq;
namespace LinqProblem
{
class Program
{
static void Main(string[] args)
{
BetterList list = new BetterList();
list.Select(l => l.ToString() == "abc"); // no compile error
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试在子类的定义中使用Select ...
using System.Collections.Generic;
using System.Linq;
namespace LinqProblem
{
class BetterList : List<string>
{
public List<string> Stuff
{
get
{
base.Select(l => l.ToString() == "abc"); // compile error
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
'
List<string>'不包含'Select'的定义.
为什么会出现这种情况,是否有解决方法?
| 归档时间: |
|
| 查看次数: |
1007 次 |
| 最近记录: |