-1

I was wondering if there is a way to find if my interface reference is a specific class.

For example i have DeviceInterface reference, and Playstation, PC and Mac all implement it. Is there a way to see if DeviceInterface is a PC?

I have thought about using a enum to define the type and using that, but is there a way of avoiding this and using a type check or something along those lines?

Thanks in advance.

Mike
  • 21
  • 4

1 Answers1

0

Let's say that you have

DeviceInterface PcDevice = new PC();

In that case you can just do:

if (PcDevice is PC) { console.WriteLine("I'm a PC"); }

read more here to understand the is and as operators better

TGN12
  • 123
  • 1
  • 8