Translate

Monday, October 15, 2007

How to do Redim of an array in C#

Since there's no ReDim keyword in C# then what needs to be done is that we need to write a function which does the same using an array list, this would be type specific :

private ParameterValue[] ReDimArray(ref ParameterValue[] ParameterValue,int Index)
{
TempParameterValue= new ParameterValue[Index+1];
if (TempParameterValue !=null && ParameterValue!=null)
Array.Copy(ParameterValue,TempParameterValue,Math.Min(TempParameterValue.Length,Index));

ParameterValue = TempParameterValue;
return ParameterValue;
}

No comments:

Post a Comment