have you ever seen during runtime that an object (C#) returns null after constructing it? [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this questionI know it is a strange question did someone have had a case where a C# object return null after newing it up?
Is this a trick question?
int? i = new int?();
if (i == null)
Console.WriteLine("It's null!");
Not possible by design, you'll always get an OutOfMemory exception if a new object cannot be created. A corrupted garbage collected heap is technically possible, invariably triggered by misbehaving unmanaged code, but I never heard of any cases where that didn't trigger an ExcecutionEngineException.
I'm thinking he's got failing logic in the constructor of his object. There's no way this is happening to an object native to the asp.net framework.
精彩评论