Monday, December 22, 2008

C# Array Functions

Array.ConvertAll- Convert integer array to string array

private void TestMethod(int[] intArray)

{

string[] stringArray =

Array.ConvertAll<int,string>

(intArray,new Converter<int,string>

(ConvertIntToString));

string result = string.Join(",", stringArray);

}

private string ConvertIntToString(int intParameter)

{

return intParameter.ToString();

}


Array.Resize

int[] zArray = { 1, 2, 3, 4 };

Array.Resize<int>(ref zArray, 8);


Array.ConstrainedCopy Method

Copies a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely.


Array.AsReadOnly Method

Returns a read-only wrapper for the specified array.

No comments: