我已經解決了它沒有列出與產卵詞典中的錯誤字段相關的數據的問題,但仍然想問一問我接近它的方式是否正常?關於linq查詢字典的Where子句?
我有幾個複選框,如果爲真應該添加檢查項目狀態並將其包括在列表中。
所以沒有真正知道做什麼,這就是我想出了:
HashSet<int> status = new HashSet<int>();
if (OptionsForm.filterPlayer.Checked) status.Add(0);
if (OptionsForm.filterEnemy.Checked) status.Add(1);
if (OptionsForm.filterSummon.Checked) status.Add(2);
if (OptionsForm.filterNPC.Checked) status.Add(3);
if (OptionsForm.filterObject.Checked) status.Add(4);
if (OptionsForm.filterMonster.Checked) status.Add(5);
if (OptionsForm.filterGatherable.Checked) status.Add(6);
if (OptionsForm.filterUnk.Checked) status.Add(7);
var query = from SpawnList item in spawnEntities.Values
where status.Contains(item.Status)
orderby item.Name ascending
select item;
但是目前我們沒有返回我應該已經返回的任何錯誤或項目。
spawnEntities是一個帶uint的字典,SpawnList。
SpawnList是一個簡單的類:
public class SpawnList
{
public string Name { get; set; }
public int Status { get; set; }
// some more data not needed for the question
}
狀態哈希集填寫是否正確? – SWeko 2010-12-21 09:33:46
當你枚舉結果時會發生什麼? – Ani 2010-12-21 09:36:27
你試過枚舉查詢(或調用'query.ToList()')?因爲LINQ查詢只在你枚舉它時執行...... – digEmAll 2010-12-21 09:39:11