This is my function:
private IEnumerable SeachItem(int[] ItemIds)
{
using (var reader = File.OpenText(Application.StartupPath + @\"
The method signature on SearchItem
indicates that the method returns an IEnumerable
but the anonymous type declared in your LINQ query is not of type string
. If you want to keep the same method signature, you have to change your query to only select string
s. e.g.
return myLine.Select(a => a.Text);
If you insist on returning the data selected by your query, you can return an IEnumerable
if you replace your return
statement with
return myLine.Cast
Then you can consume the objects using reflection.
But really, if your going to be consuming an anonymous type outside the method that it is declared in, you should define a class an have the method return an IEnumerable
of that class. Anonymous types are convenience but they are subject to abuse.