Introduce AsReadOnlyList extension to cast arrays

This commit is contained in:
ig 2023-08-16 15:14:35 +02:00
parent ea7a13da06
commit 829732a7ba
2 changed files with 7 additions and 0 deletions

View File

@ -13,4 +13,6 @@ public static class ArrayExtensions
Array.Fill(ts, element);
return ts;
}
public static IReadOnlyList<T> AsReadOnlyList<T>(this T[] ts) => ts;
}

View File

@ -277,6 +277,9 @@ public static class EnumerableUtils
public static T[] ToArray<T>(this IEnumerable<T> ts, Int32 n)
{
if (ts is T[] ta)
return ta;
var array = new T[n];
var i = 0;
@ -296,6 +299,8 @@ public static class EnumerableUtils
return ts as T[] ?? ts.ToArray(ts.Count);
}
public static IEnumerable<T> Concat<T>(this IEnumerable<T> ts, T last)
{
foreach (var t in ts)