function with n number of arguments :)

rarely we could need of such function but i m sure whilst programming, programmers have used such functions of their framework functions/base library functions e.g, in case of c language you must have used printf() function (if u didn’t use it i can say u r n’t c programmer :D) it takes n number of arguments, hmm still confuse ok let me tell u how ………..

printf(“sum of %d and %d is %d”,1,2,1+2) ; i hope now you got my point.

but what if you have to make function with n number of arguments using .net (c#.net) then don’t worry main hoon na😀 simply u would need to know/utilize PARAMS keyword of c# let me give u any example

private object Sum(params object[] numbers) {

int sum = 0;

foreach (object o in numbers)

if (o.GetType() == typeof(int))

sum += (int) o;

return (object) sum; }

i used object to make it more flexible for you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s