C#の新機能です。問題は、私が配列に対して "allowedA"と "allowedB"配列を使って、私のapi呼び出しの結果をフィルタリングする必要があるということです。ループに対してチェックするラムダ式を編集する方法がわかりません。ラムダ式を使用してC#を使用して値をフィルタリングして加算する
var activities = await _restClientTaxonomy.GetTaxonomyFullAsync(TAXONOMY_CLASSIFICATIONID_FOR_ACTIVITY);
var activityTypes = await _restClientTaxonomy.GetTaxonomyFullAsync(TAXONOMY_CLASSIFICATIONID_FOR_ACTIVITY_TYPES);
var documentEventxx = activities.Select(type => type.Id);
long [] allowedA = new long []{ 7137, 40385637};
long [] allowedB = new long []{ 7137, 40385637};
foreach (long value in documentEventxx)
{
foreach (var item in allowed)
{
if (item == value) {
//These are the values I am looking for -> values that are part of the documentEventxx and allowedB.
}
}
}
var result = activityTypes.Select(type => new CategoryViewModel
{
Id = type.Id,//This is where I want to add only items that are in the allowedA array
Text = type.Name,
Types = activities.Where(a => a.ParentId == type.Id).Select(t => new TaxonomyMemberTextItem
{
Id = t.Id, //This is where I want to add only items that are in the allowedB array
Text = t.Name
}).ToList()
}).ToArray();
ラムダ式とforeachループについて読んでいますので、ランダムリンクを投稿しないでください。
ありがとうございます。
アクティビティを試しましたか(a => a.ParentId == type.Id && allowedB.Contains(a.Id))? .Contains()をIndexOf(a.id)!= -1で変更する必要があるかもしれませんが、試してみてください。 –