USING ARRAYS AS ARGUMENTS
• Arrays can be used as arguments with methods that take variable number of parameters
• A sample implementation as shown under:
class Util
{
public static int Min(int[] paramList)
{
if(paramList == null || paramList.Length == 0)
{ Throw new ArgumentException(“Util.Min”); }
int currentMin = paramList[0];
foreach(int i in paramlist)
{
if(i < currentmin)
{ currentmin = i; }
}
return currentmin;
}
}
• To use this method: int[] arrInt = new int[2,3,4]; int min = Util.Min(arrint);
No comments:
Post a Comment