public class TwitterResponse<T>
where T : Core.ITwitterObject
{
// all properties and methods here
}
Can someone explain me what is this in simple terms ? what is “where T :Core.ITwitterObject ” part here ? Have seen this in Twitterizer source code. Any examples to better understand this ?
This means that
Tmust implement interfaceCore.ITwitterObject.If you pass to the generic a type
Tnot implementing this interface, a compile-time error occurs.This condition allows the compiler to call the functions which are declared in
Core.ITwitterObjecton instances ofT.Look at the documentation for more information.
Example:
This has an advantage over the customary
because the methods like
Firstwould be more type-safe, you won’t need to downcast fromIFootoSomeRandomFooImpl.