我们如何在C#.net中声明可选参数? [英] How can we declare Optional Parameters in C#.net?

查看:62
本文介绍了我们如何在C#.net中声明可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一种方法来执行某些操作,我希望通过使用C#中的可选参数"仅将方法编写一次,除了方法重载"之外?

I am using a method for doing some action, i want the method to be written only once by using Optional Parameters in C#, other than Method Overloading is there any?

推荐答案

Visual Studio 2010的新功能

New to visual studio 2010

命名和可选参数

例如

public void ExampleMethod(int required, string optionalstr = "default string",
int optionalint = 10)
{
}

这篇关于我们如何在C#.net中声明可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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