C# syntax - Colon after a variable name

后端 未结 2 464
别那么骄傲
别那么骄傲 2021-02-05 00:51

Quick question; I\'ve recently upgraded to VS2010, and got the new version of ReSharper.

Now, when ReSharper is giving me autocomplete options for a variable, it give me

相关标签:
2条回答
  • 2021-02-05 00:55

    The second is for C# 4.0 named arguments. And here's a link on MSDN.

    0 讨论(0)
  • 2021-02-05 01:04

    The colon is necessary to indicate parameters. In C# 4.0, you can re-order and name your parameters, optionally, but the variable name must match the prototype and have the colon postfix.

    public void Test(string something1, string something2)
    {
    }
    

    can be called as:

    Test(something2: "bar", something1: "foo");
    

    if you want

    0 讨论(0)
提交回复
热议问题