Please explain why this test passes?
[Test]
public void TestNullOps()
{
Assert.That(10 / null, Is.Null);
Assert.That(10 * null, Is.Null);
Assert.That(10 + null, Is.Null);
Assert.That(10 - null, Is.Null);
Assert.That(10 % null, Is.Null);
Assert.That(null / 10, Is.Null);
Assert.That(null * 10, Is.Null);
Assert.That(null + 10, Is.Null);
Assert.That(null - 10, Is.Null);
Assert.That(null % 10, Is.Null);
int zero = 0;
Assert.That(null / zero, Is.Null);
}
I don't understand how this code even compiles.
Looks like each math expression with null returns Nullable<T>
(e.g. 10 / null
is a Nullable<int>
). But I don't see operator methods in Nullable<T>
class. If these operators are taken from int
, why the last assertion doesn't fail?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…