I have the following class written by someone else that I'm trying to understand (I omitted the code that is not necessary for this example):
public abstract class UserControl : System.Web.UI.UserControl
public virtual bool IsAadmin(TheUser theUser)
if (Page is Page)
var page = Page as Page;
if (page != null)
The "first page" is actually a
Page property of
UserControl class your abstract
UserControl inherits from. It's of type
System.Web.UI.Page and, as per documentation, returns
a reference to the Page instance that contains the server control.
is keyword evaluates to true when
the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.
It seems that when you were debugging your code, the examined
UserControl was not contained in a page of type
Regarding the Resharper suggestion: in your original code, you are effectively casting the
Page property twice - first, when using
is keyword and second when casting it explicitly. With the code generated by Resharper, the cast only occurs once. When the
if statement evaluates to true, you can be sure that the
page variable holds a reference to the
Something.Products.Web.Page and do not have to cast it again.