This does not give a direct answer to your generalized question, but in the most likely case (or at least in the case when I was looking for an answer when I came across this SO question), where indexes is one int , this extension The method is a little cleaner than returning the string[] array, especially in C # 7.
Whatever the cost, I string.Substring() use string.Substring() against creating two char[] arrays, calling text.CopyTo() and returning two lines by calling new string(charArray) . Using string.Substring() was about twice as fast.
C # 7 Syntax
jdoodle.com example
public static class StringExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (string left, string right) SplitAt(this string text, int index) => (text.Substring(0, index), text.Substring(index)); } public static class Program { public static void Main() { var (left, right) = "leftright".SplitAt(4); Console.WriteLine(left); Console.WriteLine(right); } }
C # 6 Syntax
jdoodle.com example
Note. Using Tuple<string, string> in versions prior to C # 7 does not save a lot of verbosity, and in fact it may be easier to return an array of string[2] .
public static class StringExtensions {
dx_over_dt
source share