Solved

Optional Parameters like VB in C#

Posted on 2007-04-02
2
214 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

13 Experts available now in Live!

Get 1:1 Help Now