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?
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
does not implement IEnumerable<Account>
.
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);
You can add System.Linq namespace. Since where has been developed under this namespace, it should be added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With