Там IsAssignableFrom
метод возвращает логическое значение, указывает, является ли один тип назначаемым из другого типа.
Как мы можем не только проверить, могут ли они присваиваться от или до друг друга, но также знать тип минимальный ковариационный для наилучшего соответствия?
Рассмотрим следующий пример (С# 4.0)
-
код
// method body of Func is irrelevant, use default() instead Func<char[]> x = default(Func<char[]>); Func<int[]> y = default(Func<int[]>); Func<Array> f = default(Func<Array>); Func<IList> g = default(Func<IList>); g=x; g=y; y=x; // won't compile x=y; // won't compile // following two are okay; Array is the type for the covariance f=x; // Array > char[] -> Func<Array> > Func<char[]> f=y; // Array > int[] -> Func<Array> > Func<int[]> // following two are okay; IList is the interface for the covariance g=x; g=y;
В приведенном выше примере, что найти - это тип между char[]
и int[]
.