I have add extension method to ArraySegment as follows, but when I using it as
var lines = TextControl.Lines;
ArraySegment<String> myArrSegOfRichTextControl =
new ArraySegment<string>(lines,0,2);
I cannot find the visual studio prompt GetSegment method after I type myArrSegOfRichTextControl. So how can I call the method of the extension? Thanks.
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
}
}
class ArraySegmentExtensionshould also be a static. It must mepublic static class ArraySegmentExtension