.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Create function with variable number of arguments.

Posted By:shiv chandra       Posted Date: June 30, 2011    Points: 40    Category: ADO.NET    URL: http://www.dotnetspark.com  

Create function with variable number of arguments.
 

Sometimes it is required to pass variable number of arguments to function. Check this article. I have tried to provide example as simple as possible.

use the params keyword to create function which can be called with a variable number of arguments.

Following function accept variant arguments.
static void ListArguments (params object[] arguments)
{
   foreach (object argument in arguments)
   {
      Console.WriteLine (argument);
   }
}

How to pass variable number of arguments
public static void Main( )
{
   ListArguments ("Hello", DateTime.Now, 5.05f, "Test");
}
Output:


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend