例如
void f<C, T>(C<T> collection, T element) : where C has member method BindarySearch
我有两个问题:
ç”案 0 :(得分:1)
您å¯ä»¥ä½¿ç”¨ç•Œé¢æ¥å¼ºåˆ¶æ‰§è¡Œæ‰€éœ€çš„æˆå‘˜ï¼š
interface IHasBinarySearch<T> : ICollection<T> {
int BinarySearch(T item);
}
然åŽå¯ä»¥åƒè¿™æ ·å®šä¹‰æ³›åž‹æ–¹æ³•ï¼š
void f<C, T>(C collection, T element) where C : IHasBinarySearch<T>
æ¤æŽ¥å£å·²ç»æ˜¯ä¸€ä¸ªé€šç”¨é›†åˆï¼ˆé€šè¿‡æ‰©å±•ICollection<T>
ï¼‰ï¼Œå› æ¤æ— 需å†æ¬¡æŒ‡å®šè¯¥æ–¹æ³•çš„约æŸã€‚