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'
この場合には初期化作業をインライン可能性がどのように任意のアイデア?
あなたの質問は[this one](http://stackoverflow.com/questions/30668572/htmlgenericcontrol-attributes-in-object-initializer)と似ていますが、受け入れ可能な回答では不可能と言われています。 –