From the course: C# Essential Training 1: Types and Control Flow

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using the is expression

Using the is expression

- We go back down here, notice we did some checks around inputs being null or not null. There're other kinds of checks that we might want to do against say the type. So we're looking at the type and whether or not it's null, but we might want to do something like this. I'm going to paste a couple items in here. Line 62 and 63, I'm defining a shift worker and a manager, but notice that the variable type I'm creating is an I person. I'm saying I have a shift worker that implements I person. So my variable SW is an I person. Likewise, my MGR or manager variable is an I person. And I have a get person details method that takes an I person. In earlier versions of C-sharp, you might do something like you see here on line 68, where you would use the as keyword in order to essentially cast an object. On the left, I'm saying I have a nullable shift worker. Remember our nullable reference types now. So this is a nullable reference type. My shift worker equals P the I person that was passed in…

Contents