This
article demonstrates how to use the name and option argument in c#.
According to Microsoft definition says that Named arguments
enable you to specify an argument for a particular parameter by
associating the argument with the parameter's name rather than with the
parameter's position in the parameter list. Optional arguments
enable you to omit arguments for some parameters. Both techniques can
be used with methods, indexers, constructors, and delegates. Suppose we
have method called “myMethod”. Now how to call this method by name and optional.so here is
void myMethod(int Key = 1, string value = "")
{
Response.Write( string.Format("key = {0}, value = {1}", Key, value));
}
// myMethod()
//here we called by name
myMethod(Key: 10);
//here we called by optional
myMethod(1);
// myMethod()
No comments:
Post a Comment