Introduce AsReadOnlyList extension to cast arrays
This commit is contained in:
parent
ea7a13da06
commit
829732a7ba
|
@ -13,4 +13,6 @@ public static class ArrayExtensions
|
||||||
Array.Fill(ts, element);
|
Array.Fill(ts, element);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IReadOnlyList<T> AsReadOnlyList<T>(this T[] ts) => ts;
|
||||||
}
|
}
|
|
@ -277,6 +277,9 @@ public static class EnumerableUtils
|
||||||
|
|
||||||
public static T[] ToArray<T>(this IEnumerable<T> ts, Int32 n)
|
public static T[] ToArray<T>(this IEnumerable<T> ts, Int32 n)
|
||||||
{
|
{
|
||||||
|
if (ts is T[] ta)
|
||||||
|
return ta;
|
||||||
|
|
||||||
var array = new T[n];
|
var array = new T[n];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
|
@ -296,6 +299,8 @@ public static class EnumerableUtils
|
||||||
return ts as T[] ?? ts.ToArray(ts.Count);
|
return ts as T[] ?? ts.ToArray(ts.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static IEnumerable<T> Concat<T>(this IEnumerable<T> ts, T last)
|
public static IEnumerable<T> Concat<T>(this IEnumerable<T> ts, T last)
|
||||||
{
|
{
|
||||||
foreach (var t in ts)
|
foreach (var t in ts)
|
||||||
|
|
Loading…
Reference in New Issue