使用默认参数调用重载方法 [英] Call overload method with default parameters

查看:78
本文介绍了使用默认参数调用重载方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有两种方法

public void foo(int a, int b, bool c = false)
{
    //some code
}

public void foo(int a, int b, bool d, bool c = false)
{
    //some other code
}

当我呼叫 foo( 1,2,true)表示第一种方法。是否可以通过仅传递3个参数来调用第二种方法?

when I call foo(1,2,true) it refers to first method. Is there any way to call second method by passing only 3 parameters?

我在生产代码中发现了这样的内容:/

I found something like this in production code :/

推荐答案

foo(1,2,d:true); //will call the second method.

这篇关于使用默认参数调用重载方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆