I've written the following extension method to concatenate two IBuffer objects in a Windows Runtime application:
public static IBuffer Concat(this IBuffer buffer1, IBuffer buffer2)
{
var capacity = (int) (buffer1.Length + buffer2.Length);
var result = WindowsRuntimeBuffer.Create(capacity);
buffer1.CopyTo(result);
buffer2.CopyTo(0, result, buffer1.Length, buffer2.Length);
return result;
}
Is this the most efficient way to handle this? Is there a better or easier way?
I've reviewed Best way to combine two or more byte arrays in C# but I don't think I should be converting to and from byte arrays.