2
if (this.UserManagmentType != UserMgmtType.NONE)
{
   return (User)GetUserBaseById(userId);
}

if (this.UserManagmentType != UserMgmtType.NONE)
{
   return GetUserBaseById(userId) as User;
}

I understand the difference between casts. The first if statement should throw an invalid cast exception if the cast fails, while the second will return a null.

For identical data under heavy load in a multi-threaded environment, the first if statement will occasionally return a null, while the second if statement will always return valid data.

The other item of note is that the containing method is a WCF endpoint.

Why would the first if statement ever return null?

Thank you for any insight.

Carl
  • 83
  • 6
  • You can check this http://stackoverflow.com/questions/132445/direct-casting-vs-as-operator – 7h4ro3 Sep 17 '14 at 08:23
  • I understand the difference between (User) and as User, the question is why for the same input, is the first if statement occasionally returning null for identical inputs? – Carl Sep 17 '14 at 08:26

0 Answers0