Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 4th, 2008, 07:31 PM
Registered User
Join Date: Mar 2008
Location: Bolingbrook, IL, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generics in 3.0

I bought the Professional C# 2008 book and while it is an excellent book some sections are not easy to understand. For example, chapter 9, that introduces "Generics" and chapter 7, about "Delegate and Events" are confusing. One question related to Generics is:

Q. If almost every thing (classes, methods, interfaces, collections ...etc) can declared as Generics then why do we need
non-Generics declarations? What is the advantage or in which situation it would make sense to still use non-Generics declarations?


  #2 (permalink)  
Old May 5th, 2008, 08:30 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

There will be times when you can utilize generics, when you have a block of functionality that could apply to any or a large set of class types. Take List<T> for example. Anything can be a list, as a list is a very abstract construct. Therefore a list is a natural candidate for "genericizing".

However, consider a class that works with text parsing. The methods will always expect strings. So is there much sense in creating a class that uses generics when the type parameter for the generic will likely always be a string? That's just overkill.

Given that generics can be tricky to work with and understand, it is sensible to maintain functionality that applies to specific concrete types when appropriate. Doing so leads to more terse and readable code and decreased complexity.

Consider also that every data type is derived from System.Object. You could certainly declare every variable in your code as type 'object', but you would then require casting every time you needed to do something specific to the type instantiated (that is not inherited from System.Object). This is functional but not very user friendly.

Consider generics a specialized tool set that should be used where appropriate, but not as a replacement for existing tools.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
NET Generics FREDYCOREA .NET Framework 3.5 1 February 21st, 2008 10:17 AM
Application of generics micmit C# 2005 0 October 12th, 2006 08:10 PM
Generics Related error in my code, I think??? rodmcleay Generics 1 August 3rd, 2006 12:02 AM
Problem with generics collections demitry .NET Framework 2.0 4 November 24th, 2005 06:39 AM

All times are GMT -4. The time now is 12:39 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.