C#中的默认参数 [英] Default Parameter in C#

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

问题描述

我有一个函数

I have a function

public Email_Sender(Boolean _Activity_INSERT, String _OppID, List<String> attached_files = null,Boolean AutoSendEmail=false,String Mode_To_Send="Normal",Boolean _SuppressMessage=false)
     {}





我需要通过以下方式调用上述函数跳过默认参数(Mode_To_Send)。

我需要为最后一个参数提供值,我该如何调用上面的函数?





Prathamesh



I need to invoke the above function by skipping the default parameter (Mode_To_Send).
I need to provide value to the last parameter, how can i call the above function?


Prathamesh

推荐答案

默认参数不是C#3.0的一部分,它们仅与C#4.0一起出现。

所以,我假设您的C#3.0标签应为C#4.0。



您可以通过

a调用该功能)通过所有实际明确的参数

b)通过n传递实际参数主题参数



例如for b)

Default parameters are not part of C# 3.0, they came into existence with C# 4.0 only.
So, I assume your tag for C# 3.0 should be C# 4.0.

You may call the function by
a) passing all actual arguments explicitly
b) pass the actual arguments by means of named parameters

E.g. for b)
Email_Sender(insert, id, _SuppressMessage: suppress);



干杯

Andi


Cheers
Andi


只需创建一个过载,这样您就可以随意拨打任何一个电话:

Just create an overload, so you can simply call whichever you want:
public Email_Sender(Boolean _Activity_INSERT, String _OppID, List<String> attached_files = null,Boolean AutoSendEmail=false,Boolean _SuppressMessage=false)
{
Email_Sender(_Activity_INSERT, _OppID, attached_files, AutoSendEmail, "Normal", _SuppressMessage);
}


这篇关于C#中的默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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