10 May 2010

Visual C#.Net: Optional Parameters

Share to others:

I've been developing desktop applications in VB6 before and been using the OPTIONAL class where a parameter is not totally required in your function. However, upon developing applications in Visual C#.Net, I didn't find that option. After googling around I found out that you can also do optional parameters on your function. Here is how you can do it.

in the declarations, add this:

using System.Runtime.InteropServices;

After doing it, you may be able to use Optional class like how I used it below;

public string WhatsUp (string UrMessage, [Optional] string Name)
     if (Name != "")
          return UrMessage + ", " + Name;
          return UrMessage;

Enjoy developing applications people.


Post a Comment

Related Posts Plugin for WordPress, Blogger...