Skip to content

Instantly share code, notes, and snippets.

@rje
Created August 16, 2013 00:54
Show Gist options
  • Save rje/6246335 to your computer and use it in GitHub Desktop.
Save rje/6246335 to your computer and use it in GitHub Desktop.
List<MyBaseClass> m_listOfObjects; // initialized somewhere else
public T FindFirstObjectOfType<T>() where T: MyBaseClass
{
foreach(var toCheck in m_listOfObjects)
{
if(toCheck.getType() == typeof(T))
{
return toCheck as T;
}
}
}
public List<T> FindAllObjectsOfType<T>() where T: MyBaseClass
{
var toReturn = new List<T>();
foreach(var toCheck in m_listOfObjects)
{
if(toCheck.getType() == typeof(T))
{
toReturn.Add(toCheck as T);
}
}
return toReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment