Читайте также: |
|
Given an implicit conversion C1 that converts from an expression E to a type T1, and an implicit conversion C2 that converts from an expression E to a type T2, C1 is a better conversion than C2 if at least one of the following holds:
· E has a type S and an identity conversion exists from S to T1 but not from S to T2
· E is not an anonymous function and T1 is a better conversion target than T2 (§7.5.3.5)
· E is an anonymous function, T1 is either a delegate type D1 or an expression tree type Expression<D1>, T2 is either a delegate type D2 or an expression tree type Expression<D2> and one of the following holds:
o D1 is a better conversion target than D2
o D1 and D2 have identical parameter lists, and one of the following holds:
· D1 has a return type Y1, and D2 has a return type Y2, an inferred return type X exists for E in the context of that parameter list (§7.5.2.12), and the conversion from X to Y1 is better than the conversion from X to Y2
· D1 has a return type Y, and D2 is void returning
Better conversion from type
Given a conversion C1 that converts from a type S to a type T1, and a conversion C2 that converts from a type S to a type T2, C1 is a better conversion than C2 if at least one of the following holds:
· An identity conversion exists from S to T1 but not from S to T2
· T1 is a better conversion target than T2 (§7.5.3.5)
Better conversion target
Given two different types T1 and T2, T1 is a better conversion target than T2 if at least one of the following holds:
· An implicit conversion from T1 to T2 exists, and no implicit conversion from T2 to T1 exists
· T1 is a signed integral type and T2 is an unsigned integral type. Specifically:
o T1 is sbyte and T2 is byte, ushort, uint, or ulong
o T1 is short and T2 is ushort, uint, or ulong
o T1 is int and T2 is uint, or ulong
o T1 is long and T2 is ulong
Overloading in generic classes
While signatures as declared must be unique, it is possible that substitution of type arguments results in identical signatures. In such cases, the tie-breaking rules of overload resolution above will pick the most specific member.
The following examples show overloads that are valid and invalid according to this rule:
interface I1<T> {...}
interface I2<T> {...}
class G1<U>
{
int F1(U u); // Overload resulotion for G<int>.F1
int F1(int i); // will pick non-generic
void F2(I1<U> a); // Valid overload
void F2(I2<U> a);
}
class G2<U,V>
{
void F3(U u, V v); // Valid, but overload resolution for
void F3(V v, U u); // G2<int,int>.F3 will fail
void F4(U u, I1<V> v); // Valid, but overload resolution for
void F4(I1<V> v, U u); // G2<I1<int>,int>.F4 will fail
void F5(U u1, I1<V> v2); // Valid overload
void F5(V v1, U u2);
void F6(ref U u); // valid overload
void F6(out V v);
}
Дата добавления: 2015-11-16; просмотров: 64 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Better function member | | | Function member invocation |