私はlinqの新しいブランドです。私は経験不足のため何かが欠けていると確信しています。Linqオブジェクト列挙型
問題:私は、私はエラーunable to cast object of type System.Collections.Generic.KeyValuePair '2[Acct]' to type 'Acct'
を取得した結果を列挙しようとした場合 私はオブジェクトを照会し、列挙アカウンティングを返すためにLINQを使用していますがwhere o.Diff!=0
オブジェクト。
質問: Linqクエリから列挙可能なAcctオブジェクトを返すにはどうすればよいですか?
ありがとうございます!
public class AcctSum
{
string ID;
Decimal Amt1;
Decimal Amt2;
Decimal Diff;
ArrayList<AcctDet> lines;
}
public class AcctInfo
{
Dictionary<string,AcctSum> acct
//code that adds the data...
public iEnumerable Discrepancies()
{
var results = (from Acct a in acct
where a.Diff != 0
select a).AsEnumerable<Acct>();
foreach (var result in results)//at runtime this generates an error
{
}
return results.GetEnumerator();
}
}
あなたはAcctとAcctSumを相互交換的に使用しています。それは正しいとは思わない。 Acctが列挙型の場合は、別のものに変換することはできません。 – Schultz9999
'' from 'の 'Acct'を' variable1'のような型名でない変数名に変更し、 'AsEnumerable()'を 'AsEnumerable ()'に変更し、最後に 'in acct'を' in acct.Values' –