Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Optional Parameters like VB in C#

Posted on 2007-04-02
2
Medium Priority
?
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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