I know of is
and as
for instanceof
, but what about the reflective isInstance() method?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What Does C Programming Language (C) Mean? C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s.
C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.
bool result = (obj is MyClass); // Better than using 'as'
The equivalent of Java’s obj.getClass().isInstance(otherObj)
in C# is as follows:
bool result = obj.GetType().IsAssignableFrom(otherObj.GetType());
Note that while both Java and C# work on the runtime type object (Java java.lang.Class
≣ C# System.Type
) of an obj
(via .getClass()
vs .getType()
), Java’s isInstance
takes an object as its argument, whereas C#’s IsAssignableFrom
expects another System.Type
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With