Broken if statement
Posted
by
Vladimir Nani
on Stack Overflow
See other posts from Stack Overflow
or by Vladimir Nani
Published on 2012-10-05T13:19:39Z
Indexed on
2012/10/05
15:37 UTC
Read the original article
Hit count: 232
Maybe I am crazy but how that could be? some == null
is always false but debugger goes into if-statement body anyway. Any ideas?
- I have restarted visual studio
- I have cleaned every bin/obj folder
- It is not the case that i don`t understand that WindowsIdentity.GetCurrent() may return null. That was my first idea.
var some = new object();
if (some == null) {
throw new Exception("hi!");
}
else {
do();
}
My code:
private void GetCurrentWindowsIdentity() {
var identity = WindowsIdentity.GetCurrent()
if (identity == null) {
throw new Exception(Errors.IdentityIsNullException);
}
try {
if (CurrentAuthenticationWrapper.AuthenticationType ==
AuthenticationType.Windows) {
CurrentLogin = _identity != null ? _identity.Name : string.Empty;
}
} catch (Exception ex) {
ViewManager.ShowError(ex);
}
_identity = identity;
}
© Stack Overflow or respective owner