Quote Originally Posted by TheCPUWizard
Actually T MUST be derived from MyObject or the element could not be in the list in the first place....
No it doesn't have to be derived from MyObject. Certainly the objects in the list have to be derived from MyObject, but T could be anything.

So I might have:

Code:
class MyComparableObject : MyObject, IComparable
{
}
Then I might want to do:

Code:
IComparable comparableObject = collection.GetFirstObjectOfType<IComparable>();
So in this case, the collection can contain instances of MyComparableObject because they are derived from MyObject. No problem. However I am not interested in instances of MyObject or MyComparableObject , I am interested in any and all objects that implement IComparable which happen to include MyComparableObject.

So using:

Code:
public T GetFirstObjectOfType<T>() where T : MyObject
Won't work because IComparable is not derived from MyObject. Sure I could do:

Code:
IComparable comparableObject = collection.GetFirstObjectOfType<MyComparableObject>();
But again, that is not necessarily what I am looking for. I want IComparable.

Also using "where T : class" or "where T : Object" don't work. Actually where T : Object won't even compile because Object is a special class.