Does the is
operator indicate whether or not an object is an instance of a certain class, or only if it can be casted to that class?
Assume I have a DbCommand
called command
that has actually has been initialized as a SqlCommand
. What is the result of command is OracleCommand
?
(SqlCommand
and OracleCommand
both inherit from DbCommand
)
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.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
One of the most significant features of C language is its support for dynamic memory management (DMA). It means that you can utilize and manage the size of the data structure in C during runtime. C also provides several predefined functions to work with memory allocation.
C has the features of both assembly level languages i.e low-level languages and higher level languages. So that's why C is generally called as a middle-level Language. The user uses C language for writing an operating system and generates menu driven customer billing system.
It checks if the object is a member of that type, or a type that inherits from or implements the base type or interface. In a way, it does check if the object can be cast to said type.
command is OracleCommand
returns false as it's an SqlCommand
, not an OracleCommand
. However, both command is SqlCommand
and command is DbCommand
will return true as it is a member of both of those types and can therefore be downcast or upcast to either respectively.
If you have three levels of inheritance, e.g. BaseClass
, SubClass
and SubSubClass
, an object initialized as new SubClass()
only returns true for is BaseClass
and is SubClass
. Although SubSubClass
derives from both of these, the object itself is not an instance of it, so is SubSubClass
returns false.
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