The as
operator attempts to convert the parameter to the requested type, returning null
if the conversion/cast fails. (MSDN)
So the code you provided is checking if sender
is a Rectangle
object (or a derived type). It then checks for null before using the converted variable, which is always good practice when using as
.
Note that the second code just assigns to a different variable name, though using a class name as a variable name is strongly discouraged.
solved sender as in C# [duplicate]