C# functions and optional parameters

前端 未结 4 1480
名媛妹妹
名媛妹妹 2021-01-20 11:15

I know that in C# it is possible to define optional parameters. My question is directed at how flexible this is.

Let f be a function as below, with a

相关标签:
4条回答
  • 2021-01-20 11:40

    Using named arguments:

    f(a: 5, c: 6);
    

    Although, strictly speaking in my example, you don't have to qualify the a:

    f(5, c: 6);
    
    0 讨论(0)
  • 2021-01-20 11:53

    Try:

    f(11, c: 33)
    

    And take a look at the documentation

    0 讨论(0)
  • 2021-01-20 11:56

    You can prefix the parameter with the argument name:

    f(1, c:3);
    
    0 讨论(0)
  • 2021-01-20 11:57

    You use named parameters:

    f( a:100, c:300);
    
    0 讨论(0)
提交回复
热议问题