Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have C# error when calling:

string.Format(format:"abbccc", 1,22);

The error is "Named argument specifications must appear after all fixed arguments have been specified"

How can I fix this?

[Edit]

I prefer to use named parameters.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
415 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want to specify the name of the format argument, you have to specify the name of the following argument also:

string.Format(format:"abbccc", arg0:1, arg1:22);

That's not very useful, as the names "arg0" and "arg1" doesn't say anything at all about the arguments.

Also, there are only overloads up to "arg2", so if you have more arguments, you have to put them in an array to name the argument:

string.Format(format:"abbccc", args:new object[] { 1, 2, 3, 4 });

You can simply skip naming the arguments:

string.Format("abbccc", 1, 22);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...