Can C# support variable argument on method ?

 Posted by Chvrsri on 1/27/2011 | Category: C# Interview questions | Views: 3166 | Points: 40

Yes it can. Suppose let us take an example of

void paramsMyDemo(object arg1, object arg2, params object[] argsResult)

foreach (object arg in argsResult)
/* Some Logic */

Here params keyword is applied on a method parameter which is an array . So now if we want to invoke that method we need to pass the parameters in comma seperated list.

type.paramsMyDemo(2,0.5f, "DotNetFunda", 0.0m, new UserDefinedType());

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response