Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > BOOK: Professional .NET 2.0 Generics
| Search | Today's Posts | Mark Forums Read
BOOK: Professional .NET 2.0 Generics
This is the forum to discuss the Wrox book Professional .NET 2.0 Generics by Tod Golding; ISBN: 9780764559884
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional .NET 2.0 Generics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 19th, 2007, 04:09 AM
Registered User
 
Join Date: Aug 2007
Location: , , Russia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Guidelines Item 3: Replace System.Type with Type

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 :)



Similar Threads
Thread Thread Starter Forum Replies Last Post
An unhandled exception of type 'System.Data.SqlCli BB VB.NET 2002/2003 Basics 5 February 21st, 2014 10:22 AM
Reading the type of file system scoobie Java Basics 5 August 20th, 2009 02:35 AM
unhandled exception of type 'System.Net.WebExcepti booksnore2 C# 0 June 26th, 2004 07:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.