Skip to content

Instantly share code, notes, and snippets.

@VladimirReshetnikov
Last active January 2, 2016 23:59
Show Gist options
  • Save VladimirReshetnikov/8380121 to your computer and use it in GitHub Desktop.
Save VladimirReshetnikov/8380121 to your computer and use it in GitHub Desktop.
class Program
{
// What argument do you need to provide to this method so that it returns true?
public static bool AreYouNuts<T>(T[] array)
{
if (array == null || array.Length == 0)
return false;
var local = (T[]) array.Clone();
var x = local[0];
var y = local.GetValue(0);
return x.GetType() != y.GetType();
}
}
@VladimirReshetnikov
Copy link
Author

It is a CLR rule. See Ecma-335, Partition I, 8.7.1 Assignment compatibility for signature types:
...
7. T is a zero-based rank-1 array V[], and U is IList, and V is array-element-compatible-with W.
...
[Note: in other words, array-element-compatible-with extends compatible-with but is agnostic
with respect to enumerations and integral signed-ness. end note]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment