//www.technical-programming.com, lorenz lo sauer, 2013
//description: extending C# for fast and easy string extension
//note: part of a larger Open-Source Project-Codebase
//resides in IEnumerableGenericExtension.cs
public static class IEnumerableGenericExtension
{
public static IEnumerable<T> Append<T>(this T[] arrayInitial, T[] arrayToAppend) where T : System.Collections.IEnumerable
{
if (arrayToAppend == null) {
throw new ArgumentNullException("The appended object cannot be null");
}
if ((arrayInitial is string) || (arrayToAppend is string)) {
throw new ArgumentException("The argument must be an enumerable");
}
T[] ret = new T[arrayInitial.Length + arrayToAppend.Length];
arrayInitial.CopyTo(ret, 0);
arrayToAppend.CopyTo(ret, arrayInitial.Length);
return ret;
}
}
//www.technical-programming.com, lorenz lo sauer, 2013
//description: extending C# for fast and easy string extension
//note: part of a larger Open-Source Project-Codebase
//resides in IEnumerableStringExtensions.cs
public static class IEnumerableStringExtensions
{
public static IEnumerable<string> Append(this string[] arrayInitial, object objectToAppend)
{
string[] objectArray = null;
if(!(objectToAppend is string) && (objectToAppend is System.Collections.IEnumerable)){
objectArray = (string[])objectToAppend;
}else if(objectToAppend is string){
objectArray = new string[]{(string)objectToAppend};
}else{
throw new ArgumentException("No valid type supplied.");
}
string[] ret = new string[arrayInitial.Length + objectArray.Length];
arrayInitial.CopyTo(ret, 0);
objectArray.CopyTo(ret, arrayInitial.Length);
return ret;
}
}
//example usage
var someStringArray = new[]{"a", "b", "c"};
var someStringArray2 = new[]{"d", "e", "f"};
someStringArray.Append(someStringArray2 ); //contains a,b,c,d,e,f
someStringArray.Append("test"); //contains a,b,c,test
//www.technical-programming.com, lorenz lo sauer, 2013
//description: extending C# for fast and easy string extension
//note: part of a larger Open-Source Project-Codebase
//see: http://stackoverflow.com/questions/59217/merging-two-arrays-in-net
//resides in IEnumerableStringExtensions.cs
public static class IEnumerableStringExtensions
{
public static IEnumerable<string> Append(this string[] arrayInitial, object arrayToAppend)
{
string[] ret = new string[arrayInitial.Length + arrayToAppend.Length];
arrayInitial.CopyTo(ret, 0);
arrayToAppend.CopyTo(ret, arrayInitial.Length);
return ret;
}
}
//example usage
var someStringArray = new[]{"a", "b", "c"};
var someStringArray2 = new[]{"d", "e", "f"};
someStringArray.Append(someStringArray2 ); //contains a,b,c,d,e,f