如何跳过在C#中的可选参数? [英] How to skip optional parameters in C#?
本文介绍了如何跳过在C#中的可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
public int foo(int x, int optionalY = 1, int optionalZ = 2) { ... }
我想这样称呼它:
int returnVal = foo(5,,8);
在换句话说,我想提供 X
和以Z
,但我想使用是
, optionalY = 1的默认。
In other words, I want to provide x
and z
, but I want to use the default for Y
, optionalY = 1.
Visual Studio的不喜欢 ,,
Visual Studio does not like the ,,
请帮忙。
推荐答案
如果这是C#4.0中,可以使用指定的参数的特点:
If this is C# 4.0, you can use named arguments feature:
foo(x: 5, optionalZ: 8);
请参阅的this博客了解详情。
这篇关于如何跳过在C#中的可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文