Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set named argument for string.Format?

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.

like image 860
Nam G VU Avatar asked Oct 30 '10 15:10

Nam G VU


People also ask

What is the argument specifier for a string?

The % symbol is used in Python with a large variety of data types and configurations. It is used as an argument specifier and string formatter.

What is string format () used for?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string.

What does mean {} format in Python?

Definition and Usage The format() method formats the specified value(s) and insert them inside the string's placeholder. The placeholder is defined using curly brackets: {}.

How do you format a string in Python?

To use formatted string literals, begin a string with f or F before the opening quotation mark or triple quotation mark. Inside this string, you can write a Python expression between { and } characters that can refer to variables or literal values.


2 Answers

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);
like image 52
Guffa Avatar answered Nov 15 '22 20:11

Guffa


In my case, I had to Clean and Rebuild the solution, that made the error go away. What happened was, I added an argument like this

sched.ScheduleJob(Jobdetail:job, trigger); 

I was getting an error for trigger, so I removed, JobDetail:, and the syntax error go away but on complication I was still getting the error

Named argument specifications must appear after all fixed arguments have been specified

I cleaned the solution and rebuilt and the error went away.

like image 1
Hammad Khan Avatar answered Nov 15 '22 21:11

Hammad Khan