Solved

Optional Parameters like VB in C#

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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