How to set named argument for string.Format?

后端 未结 2 1719
离开以前
离开以前 2020-12-20 13:35

I have C# error when calling:

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

The error is \"Named argument specifications must appear after al

相关标签:
2条回答
  • 2020-12-20 13:58

    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.

    0 讨论(0)
  • 2020-12-20 14:01

    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);
    
    0 讨论(0)
提交回复
热议问题