This question is specifically about generic methods (not classes).
What is the difference between the following two statements?
public bool MyMethod<T>(T t) where T : IMyInterface {}
public bool MyMethod(IMyInterface t) { }
The first statement defines a generic method and constrains the type, the second one is a non generic method and specifies the type of the parameter. Why would you use one over the other?
Or, similar example:
public class LibraryItem
{
public string Title;
public int Stock;
}
public void CheckIn<T>(T item) where T : LibraryItem
{
item.Stock += 1;
}
public void CheckIn2(LibraryItem item)
{
item.Stock += 1;
}
Again, what would be the advantage of using the generic version over the non-generic version?