我确定我以前做过这个,但找不到任何例子!哎呀...
例如,我想将IList
a 转换为BindingList
:
public class ListHelper { public static BindingListToBindingList(IList data) { BindingList output = new BindingList (); foreach (T item in data) output.Add(item); return output; } }
Sander.. 34
ToBindingList(...)
public class ListHelper { public static BindingListToBindingList (IList data) { BindingList output = new BindingList (); foreach (T item in data) { output.Add(item); } return output; } }
bruno conde.. 11
这不是更简单吗?
public static class Extensions { public static BindingListToBindingList (this IList list) { return new BindingList (list); } }
这很简单,我们不需要扩展方法......
我错过了什么吗?
ToBindingList(...)
public class ListHelper { public static BindingListToBindingList (IList data) { BindingList output = new BindingList (); foreach (T item in data) { output.Add(item); } return output; } }
这不是更简单吗?
public static class Extensions { public static BindingListToBindingList (this IList list) { return new BindingList (list); } }
这很简单,我们不需要扩展方法......
我错过了什么吗?
你可以通过扩展方法来做到这一点,它会更好.
public static class Extensions { public static BindingListToBindingList (this IList list) { BindingList bindingList = new BindingList (); foreach (var item in list) { bindingList.Add(item); } return bindingList; } }