Say I have a list of objects called components:
List<object> components = new List<object>();
Say it’s populated with objects of the classes engine, wheel, frame. Now, I want to make a function that takes a class as a parameter and returns true if the list has an object of that class. Like this:
public static bool HasComponent( *the class* ) {
foreach(object c in components) {
if(c is *the class*)
return true;
}
return false;
}
How do i go about doing that? is it possible?
Use generics:
Call it: