There is a operator in java to check whether one object is an instance of a class or of that type. Is there a method similar to this in c#. Or do we create a custom method that does that.
Asked
Active
Viewed 38 times
0
-
use this method typeof() – CodingMytra Jun 24 '22 at 10:54
-
`if (value is MyClass myClass) {/* Relevant Code with myClass here */}` – Dmitry Bychenko Jun 24 '22 at 10:56
-
Check `is`, `as`, `typeof` and `GetType()` – Roman Jun 24 '22 at 10:56
-
Do you need strict type equality? Say we have an object of type `B` that inherits from `A`, are you looking from something that will say `true` for both `A` and `B` or only for `B`? If the former, `is` should work fine, if the latter, you'd probably have to go with `.GetType()` – Rafalon Jun 24 '22 at 11:09
-
Oh thanks and what doe GetType do? Does it like sort of check the type of the object in the parameters. How would that work?. Um not necessarily strict equality. Anyways thanks for the help – The_emporer Jun 25 '22 at 07:53