本文介绍了不包含Where的定义,没有扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经寻找了一段时间来解决我的问题,并且我正在使用System.Linq 添加,除了我已经在那儿了,所以我不知道是什么我的代码未编译.在我的代码上下文中,存在 _accountreader ,为什么为什么说不存在它的定义?

So I've looked around for awhile for the answer to my problem, and I'm seeing to add using System.Linq, except I already have that there so I don't know what my code isn't compiling. In my context of code, _accountreader exists, so why is it saying no definition of it exists?

return _accountReader.Where(x => x.Age); 是编译器对我大喊的地方.

The line return _accountReader.Where(x => x.Age); is where the compiler yells at me.

public interface IAccountReader
{
    IEnumerable<Account> GetAccountFrom(string file);
}

public class XmlFileAccountReader : IAccountReader
{
    public IEnumerable<Account> GetAccountFrom(string file)
    {
        var accounts = new List<Account>();
        //read accounts from XML file
        return accounts;
    }
}

public class AccountProcessor
{
    private readonly IAccountReader _accountReader;
    public AccountProcessor(IAccountReader accountReader)
    {
        _accountReader = accountReader;
    }
    public IEnumerable<Account> GetAccountFrom(string file)
    {
        return _accountReader.Where(x => x.Age);
    }
}

public class Account
{
    public int Age { get; set; }
}

推荐答案

IAccountReader 未实现 IEnumerable< Account> .

由于您提供了方法 GetAccountFrom ,因此您也可以使用以下方法:

Since you have provided a method GetAccountFrom you could also use this:

public IEnumerable<Account> GetAccountFrom(string file)
{
    return _accountReader.GetAccountFrom(file).Where(x => x.Age);
}

除此之外, 其中 不正确,您需要提供一个谓词,例如:

Apart from that the Where is incorrect, you need to provide a predicate, for example:

.Where(x => x.Age <= 10);

这篇关于不包含Where的定义,没有扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:32