The params keyword lets you specify a method parameter that takes a variable number of arguments.
No additional parameters are permitted after the params keyword in a method declaration, and only one params keyword is permitted in a method declaration.
You can send a comma-separated list of arguments of the type specified in the parameter declaration, or an array of arguments of the specified type. You also can send no arguments
Example :
public static void UseParams(params int[] list)
{
for (int i = 0; i < list.Length; i++)
{
Console.Write(list[i] + " ");
}
Console.WriteLine();
}
We can call above method
Way 1 :
// You can send a comma-separated list of arguments of the specified type.
UseParams(1, 2, 3, 4);
Way 2 :
// An array argument can be passed, as long as the array
// type matches the parameter type of the method being called.
int[] myIntArray = { 5, 6, 7, 8, 9 };
UseParams(myIntArray);
Way 3:
UseParams();
Popular Posts
-
Cache Callback provides an ability where by some actions can be performed when that item is removed from cache CacheItemRemovedCallback ex...
-
XML DOM loads the entire xml document into memory whereas Simple API for XML ( SAX ) does not load entire xml document into memory XML DOM ...
-
Different types of diagrams in UML : UseCase diagram Class diagram Object diagram State diagram Sequence diagram Collaboration diagram...
-
Virtual-Override and New Class Child inherits from Class Parent and has mehtod ShowVirtualOverride() and ShowNew() methods. Please see th...
-
Question : Name few C# 3.0 enhancements ? Answer : The C# 3.0 language enhancements are as follows: Implicitly typed local variables I...
-
If locaction attribute is specified, must be one of: Any, Client, Downstream, None, Server or ServerAndClient.
No comments:
Post a Comment