Solved

Optional Parameters like VB in C#

Posted on 2007-04-02
2
217 Views
Last Modified: 2013-12-16
Hi all,
This may be a silly question, but:
Is there a way in C# to do a function call with an OPTIONAL argument like in VB?
For instance, in VB I can do this:
Public Function SubName(strName as string, optional strEmail as string = "") as Boolean
   SubName = False
    If strEmail <> "" then
      SubName = True
   End If
End Function
How can I do this in C#?

0
Comment
Question by:ericlockshine
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 18838277
you need overloading:

Public bool SubName(strName as string, string  strEmail)
   SubName = (strEmail != String.empty)
End Function

Public bool SubName(strName as string)
   Return SubName(strName, String.Empty)
End Function
0
 

Author Comment

by:ericlockshine
ID: 18838309
Thanks, I appreciate it!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now