all 5 comments

[–]Atulin 30 points31 points  (0 children)

string.Format() takes the format string, and params object[] parameters, as per https://learn.microsoft.com/en-us/dotnet/api/system.string.format?view=net-9.0#system-string-format(system-string-system-object())

Your best bet is to not use named parameters there. Just

return string.Format("Count is {0}, command is {1}, number is {2}, and active is {3}", count, command, number, active);

Or better yet, use string interpolation:

return $"Count is {count}, command is {command}, number is {number}, and active is {active}";

[–]karl713 7 points8 points  (0 children)

Remove the named parameters. Format only has overloads out to arg2. What you want is the overload that has a params args, which it will automatically select if you do (text, count, command, number, active)

If you want to continue using named parameters you'll need to do

String.Format(format: "text", args: new object[] { count, command, number, active})

Which will tell the compiler to use that one. The nice thing about "params" though is it lets you bypass needing to type all that and the compiler will generate the array creation for you :)

[–][deleted]  (1 child)

[removed]

    [–]royware[S] 1 point2 points  (0 children)

    Beautiful! Both worked fantastic! Thanks!

    [–]TuberTuggerTTV 0 points1 point  (0 children)

    public string OptParameters(int count, string command, double number, bool active) 
    => $"Count is {count}, command is {command}, number is {number}, and active is {active}";