没有内联数组的C#参数会导致错误"在指定了所有固定参数后,必须出现命名参数规范"

时间:2016-03-25 08:39:10

标签: c# default-parameters params-keyword

我创建了一个名为" tag"的方法。返回一个HtmlTag对象并获得#34; HtmlTag"类型的参数。 (见下文)。

我试图在没有内联数组的情况下传递params,但是我得到一个错误:"在指定了所有固定参数后,必须出现命名参数规范"。

只有将参数插入内联数组(我真的不想这样)才能解决错误。

我不能没有数组传递params吗?

protected HtmlTag tag(string tagName, string id = null, string classes = null, 
     Dictionary<string, object> attributes = null, Dictionary<string, object> data = null, 
     string text = null, params HtmlTag[] content)
{yada yada...}

请参阅下文,我如何从上面调用该方法:

tag("form", "", attributes: ObjList("...."), content: 
                    tag("input", "token", attributes: ObjList("..." + token + "...")),
                    tag("label", "...", attributes: ObjList("..."), text: "..."),
                    tag("...", "...", attributes: ObjList("...")));

插入&#34;内容&#34;我没有错误在HtmlTag的内联数组中的params值(见下文):

tag("form", "", attributes: ObjList("...."), content: new HtmlTag[] {
                    tag("input", "token", attributes: ObjList("..." + token + "...")),
                    tag("label", "...", attributes: ObjList("..."), text: "..."),
                    tag("...", "...", attributes: ObjList("..."))});

1 个答案:

答案 0 :(得分:0)

感谢Nyerguds和Jcl,我正在使用重载方法作为答案。 似乎它是唯一的方法(除了内联数组)