c# added extension method but cannot use it -
i have add extension method arraysegment follows, when using
var lines = textcontrol.lines; arraysegment<string> myarrsegofrichtextcontrol = new arraysegment<string>(lines,0,2); i cannot find visual studio prompt getsegment method after type myarrsegofrichtextcontrol. how can call method of 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 } }
extension methods must defined on static class. official documentation:
- define static class contain extension method.
try defining class this:
public static class arraysegmentextension { ... }
Comments
Post a Comment