Hello everyone. Can anyone point me what is a big deal in 3rd guidelines item? Tod advices to use:
Code:
public T FindPerson<T>(T personType, int id) {}
instead of
Code:
public object FindPerson(Type personType, int id) {}
The thing I can't understand is why is the first piece of code is better. Let's imagine we have a class named PersonFinder and it has the FindPerson method. So what would be the usage of this method? It will look something like this:
Code:
PersonFinder finder = new PersonFinder();
Employee employee = new Employee();
finder.FindPerson<Employee>(employee, 1);
See? I can't call method FindPerson if I don't provide an instance of the Employee class. But that's stupid! I can understand the following signature, without generic type:
Code:
public T FindPerson<T>(int id) {}
But there is no big difference for me where the type parameter will be: in method parameter or signature.
Can anyone point me what I missed?
P.S. By the way, the rest of the book is great :)