Optional Parameter
-
Hi friends, I need to declere some optional parameter to the function. Is it any possible to fix the problem. Thanks & Regards, MAHESH
-
Hi friends, I need to declere some optional parameter to the function. Is it any possible to fix the problem. Thanks & Regards, MAHESH
-
Hi friends, I need to declere some optional parameter to the function. Is it any possible to fix the problem. Thanks & Regards, MAHESH
Assuming you are talking about C#, optional parameter may mean 2 things: 1. You have method overloads, where certain parameters are defaulted:
public void DoThis(string name)
{
DoThis(name, true);
}public void DoThis(string name, bool someTest)
{
// ...
}2. You are talking about a feature that's being introduced in C#4.0, so you can have a signature that looks like this:
public void DrawMyLine(int x1, int y1, int x2, int y2, Color color = new Color())
{
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Assuming you are talking about C#, optional parameter may mean 2 things: 1. You have method overloads, where certain parameters are defaulted:
public void DoThis(string name)
{
DoThis(name, true);
}public void DoThis(string name, bool someTest)
{
// ...
}2. You are talking about a feature that's being introduced in C#4.0, so you can have a signature that looks like this:
public void DrawMyLine(int x1, int y1, int x2, int y2, Color color = new Color())
{
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Optional Parameters in sense Default parameter like in VB public myfunction(byval s as string,
optional
byval arr string(,))as string in C#: public string myfunction(string QryName, [Optional, DefaultParameterValue({"",""})] string[,] Qry) { .... } I tried to use this code but it shoming error.Here i'll make this Qry as a OPtional one Thanks in advance
-
Optional Parameters in sense Default parameter like in VB public myfunction(byval s as string,
optional
byval arr string(,))as string in C#: public string myfunction(string QryName, [Optional, DefaultParameterValue({"",""})] string[,] Qry) { .... } I tried to use this code but it shoming error.Here i'll make this Qry as a OPtional one Thanks in advance
-
This feature will be available only in .NET 4.0. Are you using Visual Studio 2010 Beta? What error are you getting.
The Error is The type of the argument to the DefaultValue attribute must match the parameter type Thanks
-
The Error is The type of the argument to the DefaultValue attribute must match the parameter type Thanks
-
Hi friends, I need to declere some optional parameter to the function. Is it any possible to fix the problem. Thanks & Regards, MAHESH
C# would not support that but VB.NET has support for that. Your best bet would be to go in for overloads.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
Hi friends, I need to declere some optional parameter to the function. Is it any possible to fix the problem. Thanks & Regards, MAHESH
Current versions of C# do not support optional parameters. This functionality will not be released until Visual Studio 2010 and .NET 4.0 comes out.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...