DotNetLib.ArrayExtensions

Variety of helper methods and extensions to assist when dealing with arrays.

IsNullOrEmpty

Checks an array of any type to see if it is null or has zero length
string[] arrayOfStrings;
bool isNull = ArrayExtensions.IsNullOrEmpty(arrayOfStrings);
// isNull will be true here

int[] arrayOfInts = new int[] { };
isNull = ArrayExtensions.IsNullOrEmpty(arrayOfInts);
// isNull will be true here

object[] arrayOfObjects = new object[] { "String 1" };
isNull = ArrayExtensions.IsNullOrEmpty(arrayOfObjects);
// isNull will be false here
Home

ToDelimitedString (extension)

Formats an array as a string, each element delimited by a seperator.
decimal values = new decimal[] {12, 13.45, 15};
string result = values.ToDelimitedString("{0:c}", ", ");
// result will be "$12.00, $13.45, $15.00" here
Home

ToHexString (extension)

Converts a byte array to a string based hexadecimal representation.
byte[] buffer = new byte[] { 0, 255 };
string hexString = buffer.ToHexString();
// hexString will be "00ff" here
Home

Combine

Combines a series of arrays of the same type into a single array.
int[] first = new int[] {1, 2, 3};
int[] second = new int[] {4, 5, 6};
int[] third = new int[] {7, 8, 9};
int[] fourth = new int[] {10, 11, 12};
int[] result = ArrayExtensions.Combine(first, second, third, fourth);
// result will be {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} here
Home

Last edited May 12, 2009 at 1:00 AM by joshucar, version 3

Comments

No comments yet.