Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 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
 
Old April 11th, 2006, 08:08 PM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
Default .NET 2.0 article: Understanding Generic Classes

Still wondering what generics are? How to make the transition to thinking in generics? From the best-kept secret in .NET 2.0 Programming, Professional .NET 2.0 Generics, Tod Golding's excerpt Understanding Generic Classes helps you make the transition to writing your own generic types. Here's the beginning of the excerpt:

Many developers will view themselves primarily as consumers of generics. However, as you get more comfortable with generics, you're likely to find yourself introducing your own generic classes and frameworks. Before you can make that leap, though, you'll need to get comfortable with all the syntactic mutations that come along with creating your own generic classes. Fortunately, you'll notice that the syntax rules for defining generic classes follow many of the same patterns you've already grown accustomed to with non-generic types. So, although there are certainly plenty of new generic concepts you'll need to absorb, you're likely to find it quite easy to make the transition to writing your own generic types.

Read the rest of the excerpt here.

Jim Minatel
Senior Acquisitions Editor
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Jim's Book of the week: No book this week - Donate to the Red Cross!
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Did someone here help you? Click on their post!
 
Old May 4th, 2007, 07:30 AM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

When programming, to keep components generic (applicable to all classes developed), you have to convert objects to a less descriptive version (and Object object) and then convert it back to the type you were using before. This is a little bit of a pain because normally you store objects of the same type.

Think of this.

When you store money in the bank, you give them the money and its stored no problems. When it comes back out the teller normally says "how do you want your money?", and you have to tell her "in cash.". Well, perhaps you'll always want it in cash, she'll still have the same conversation with you over and over and over again.

In object-orientated programming, you always need to cast (i.e. specify) what you want back because the computer has just stored it as an object (undescriptive "thing").

So the process of storage is:

1) Store what you want.

The process of retrieval is

1) Get the data back
2) Convert it back to the format you want.

Does sound too bad, but if you are ALWAYS storing the same time in a collection, and you will always add and remove strings then there would hopefully be a way of specifying it - which is what generics are.

Your book should cover plenty of examples.

Generics also offer a performance improvement as you do not have to convert from one type to another.

Hope this helps,

Dominic





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nice Article on Generic Paging jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 August 15th, 2007 10:49 AM
Error in BLL.Article.Article.cs drohm BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 14th, 2006 09:56 AM
New excerpt article: Using Generic Methods jminatel C# 2005 0 May 5th, 2006 04:23 PM
Excerpt article: Using Generic Methods jminatel .NET Framework 2.0 0 May 5th, 2006 04:19 PM
Excerpt: Understanding Generic Classes jminatel C# 2005 0 April 11th, 2006 08:12 PM





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