c# secret reserved words

Have you ever wondered how to write a c# class function that has an unlimited number of parameters?

The first association that comes to mind is to use the "params" keyword,
however as you probably know it allows only one type to be passed.
We can use "object" for this purpose, though there might be a better solution:
The undocumented __arglist c# keyword.

protected void Page_Load(Object sender, EventArgs e)
{
     int x=85;
     string y = "a stringy thingy";
     double d=19.45;
     WriteToPage(__arglist(x,y,d));
}
public void WriteToPage(__arglist)
{
     ArgIterator ai = new ArgIterator(__arglist);
     while(ai.GetRemainingCount() >0)
     {
         TypedReference tr = ai.GetNextArg();
         Response.Write(TypedReference.ToObject(tr)+"   ");
     }
}

Post a Comment

Previous Post Next Post