0
Is there any way of detecting if there is an perticular inherited class within an array of a class which said perticular class is derived from ?
For instance: We have an array of the type Fruit Is there a way to check if inside that array is an object of the type Apple Note: Apple is derived from Fruit public class Apple : Fruit {}
3 Respuestas
+ 1
To check if the an object inherited from base class .Try to access the property or method of the base class. In this case , apple.fruitpropety or apple . fruitmethod , if you can access them that means apple inherited from fruit.
+ 1
You can iterate through fruit array and check element is apple or not like
If(fruitarray[i] is Apple)
// your code if its an apple
0
Can't i just type "if(X is Apple){}" where x is an apple class