2
我有添加的擴展方法ArraySegment如下,但在使用它作爲C#添加的擴展方法,但不能用它
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
}
}
'類ArraySegmentExtension'也應該是靜態的。它必須我'公共靜態類ArraySegmentExtension' – lexeRoy 2013-04-06 03:51:25