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

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Params in C#.net

Posted By:volvo       Posted Date: November 14, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

The params keyword is specified before the array type declaration in a parameter list in a method. You can use the params keyword on instance or static methods. It must be the last argument in the parameter list

static void Main()
	// Call params method with one to four integer constant parameters.
	int a= AddParameters(1);
	int b = AddParameters(1, 2);
	int c = AddParameters(3, 3, 3);
	int d = AddParameters(2, 2, 2, 2);
	// Write results of the method invocations.

    static int AddParameters(params int[] values)
	// Loop through and sum the integers in the array.
	int total = 0;
	foreach (int value in values)
	    total += value;
	return total;


Further Readings:


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