3
我想初始化WebControl
对象,但是对于某些字段,这有点棘手。例如,当我尝试初始化一个TextBox
对象的Attributes
属性是这样的:使用集合初始值设定项初始化WebControl对象的属性属性
using System.Web.UI.WebControls;
Panel panel = new Panel() { Controls = { new TextBox() { Attributes = { { "key", "value" } } } } };
我得到的错误:
Cannot initialize type ' AttributeCollection ' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
任何想法,怎么可能在这种情况下,内联初始化工作?
你的问题听起来像[这一个](http://stackoverflow.com/questions/30668572/htmlgenericcontrol-attributes-in-object-initializer),并接受的答案说,这是不可能的。 –