Hi Friends i have a list of objects private static List<Transaction> transactions;
i am querying through the list to filter the data with some criteria. but i am not able to return the list string. i am getting the error
Unable to cast object of type <>f__AnonymousType1`6[System.Int32,System.String,System.String,System.String,System.String,System.String] to type 'System.String'.
my plan is to make the datagridview source this list like dataGridView2.DataSource = BasicClass.banksearch("ABC");
public static List<string> banksearch(string bankname, string sdate = null, string edate = null, string condition = null)
{
List<string> returnstr = new List<string>();
if (sdate == null && edate == null)//only bank
{
returnstr = transactions
.Where(t => t.BankName == bankname)
.Select(t => new
{
TransactionID = t.TransactionID,
BankName = t.BankName,
TemplateModel = t.TemplateModel,
Date = t.Date.ToString(),
PayeeName = t.PayeeName,
Amount = t.Amount.ToString()
}).Cast<String>().ToList();
}
return returnstr;
}
my class file is
class Transaction
{
public int TransactionID { get; set; }
public string BankName { get; set; }
public string TemplateModel { get; set; }
public DateTime Date { get; set; }
public string PayeeName { get; set; }
public decimal Amount { get; set; }
}
Please give me idea to get the result
string? I think you may really want to return aList<Transaction>return transactions.Select(t => t.BankName == bankname).ToList();?