我已将扩展方法添加到 ArraySegment 如下,但是当我将其用作
var lines = TextControl.Lines;
ArraySegment<String> myArrSegOfRichTextControl =
new ArraySegment<string>(lines,0,2);
键入 myArrSegOfRichTextControl 后,我找不到 Visual Studio 提示 GetSegment 方法。那么如何调用扩展的方法呢?谢谢。
namespace ArraySegmentExtension
{
class ArraySegmentExtension
{
#region ArraySegment related methods
public static ArraySegment<T> GetSegment<T>(this T[] array, int from, int count)
{
return new ArraySegment<T>(array, from, count);
}
public static ArraySegment<T> GetSegment<T>(this T[] array, int from)
{
return GetSegment(array, from, array.Length - from);
}
public static ArraySegment<T> GetSegment<T>(this T[] array)
{
return new ArraySegment<T>(array);
}
public static IEnumerable<T> AsEnumerable<T>(this ArraySegment<T> arraySegment)
{
return arraySegment.Array.Skip(arraySegment.Offset).Take(arraySegment.Count);
}
public static T[] ToArray<T>(this ArraySegment<T> arraySegment)
{
T[] array = new T[arraySegment.Count];
Array.Copy(arraySegment.Array, arraySegment.Offset, array, 0, arraySegment.Count);
return array;
}
#endregion
}
}