我想在列表框中顯示所有類型的控件(不重複)。我可以使用LINQ來獲取我的表單中的各種控件嗎?
我嘗試這樣做:
var controls = from c in this.Controls
select c;
foreach (var x in controls)
{
StringBuilder sb = new StringBuilder();
sb.Append(x);
listBox1.Items.Add(sb.ToString());
}
它不工作。 :(
編輯:
Error: Could not find an implementation of the query pattern for source type 'System.Windows.Forms.Control.ControlCollection'.
'Select' not found. Consider explicitly specifying the type of the range variable
什麼不工作?有沒有錯誤? – RPM1984 2010-11-11 05:12:39
here:'無法找到源類型'System.Windows.Forms.Control.ControlCollection'的查詢模式的實現。 '選擇'未找到。考慮明確指定範圍變量的類型「 – yonan2236 2010-11-11 05:14:35