aewarnick Posted February 26, 2003 Posted February 26, 2003 I see that some methods have optional parameters. How do I do that? Quote C#
Leaders quwiltw Posted February 26, 2003 Leaders Posted February 26, 2003 myClass.myMethod(Optional someParam As String = "") Quote --tim
Heiko Posted February 26, 2003 Posted February 26, 2003 I'd rather overload. Public Function myMethod () as string Public Function myMethod (aParm as string) as string Public Function myMethod (anObj as object) as string Quote .nerd
aewarnick Posted February 26, 2003 Author Posted February 26, 2003 That is probably VB and I don't think you quite know what I mean. I guess the only way is to use method overloading, right? I see someone already posted that. Ok, got my answer. Quote C#
Leaders quwiltw Posted February 26, 2003 Leaders Posted February 26, 2003 That is probably VB and I don't think you quite know what I mean. It works in VB.NET, being a .NET related forum, I generally try to provide answers that work in .NET. I guess the only way is to use method overloading, right? Ummm... NO. Method overloading is probably a better approach to getting the functionality you require, but the Optional keyword is there just as I said above -- it is exactly what you asked for btw. Quote --tim
aewarnick Posted February 26, 2003 Author Posted February 26, 2003 Do you have any idea how I would write that optional parameter in C#? I tried a few things but could not get it to compile. Quote C#
Leaders quwiltw Posted February 26, 2003 Leaders Posted February 26, 2003 You can't. You didn't say C# was the language of choice. Optional is a VB.NET keyword so as I said above it works in VB.NET. Quote --tim
*Gurus* divil Posted February 26, 2003 *Gurus* Posted February 26, 2003 C# doesn't support Optional parameters, your only choice is to use function overloading (a better design anyway). Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 26, 2003 Author Posted February 26, 2003 Ok, sounds good to me. Thanks everyone. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.