Reputation: 9
I have a this method
public void downloadAndSendFile(string fileType,
bool IsSendMail = false,
string toEmail = "",
string subject = "")
{
}
I want to do this,
IsSendMail = true
while calling this method, then toEmail
and subject
arguments are compulsoryUpvotes: 0
Views: 61
Reputation: 1
public void downloadAndSendFile(string fileType,
bool IsSendMail,
string toEmail,
string subject)
{
if(IsSendMail)
{
... code ...
Console.WriteLine(toEmail + subject);
}
else
{
... code ...
}
}
Upvotes: 0
Reputation: 271040
What about using 2 overloads of the method instead?
public void downloadAndSendFile(string fileType)
and
public void downloadAndSendFile(string fileType,
string toEmail,
string subject)
My reasoning behind this is that you don't need the IsSendMail
parameter at all. All it indicates is whether there will be 2 more arguments in the method call. If that's all it does, why not remove it and do different things depending on the parameters passed in instead? If you need the value of IsSendMail
inside the method, you can assume that it is true in the second overload, and false in the first overload.
Upvotes: 2