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 {}

9th Aug 2016, 4:40 PM
Ikarus
Ikarus - avatar
3 odpowiedzi
+ 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.
24th Aug 2016, 2:55 AM
Daryoes Mekonnen
Daryoes Mekonnen - avatar
+ 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
9th Sep 2016, 6:40 AM
Krishna
0
Can't i just type "if(X is Apple){}" where x is an apple class
4th Nov 2016, 9:03 PM
Ikarus
Ikarus - avatar