473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

C# Generics Book


I'm not the sharpest knife in the drawer, but not a dummy either.

I'm looking for a good book which goes over Generics in great detail.
and to have as a reference book on my shelf.

Personal Experience Only, Please.

...

My 1.1 CollectionBase objects look like this most of the time.

I'm trying to determine if I can *always* get the *exact same* functionality
with generics.......

public class CustomerCollection : System.Collections.CollectionBase
{

public void Add ( BusinessObjects.Customer cust )
{
base.InnerList.Add(cust);
}

public BusinessObjects.Customer this[int index]
{
get
{
return (BusinessObjects.Customer )base.InnerList[index];
}
}
public BusinessObjects.Customer Contains( string custId )
{

foreach( BusinessObjects.Customer item in base.InnerList )
if( item.CustomerID .Equals(custId) )
{
return item;
}
return null;
}
public BusinessObjects.Customer Remove(string custId)
{
// remove the object, but also return it.

BusinessObjects.Customer returnObject = null;
returnObject = this.Contains(custId);
if (null != returnObject )
{
base.InnerList.Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(object value)
{
base.OnValidate(value);
if (!(value is BusinessObjects.Customer))
{
throw new ArgumentException("Collection only supports Customer
objects.");
}
}
}
May 24 '06 #1
9 5918
On Wed, 24 May 2006 16:25:29 -0400, "sloan" <sl***@ipass.net> wrote:

I'm not the sharpest knife in the drawer, but not a dummy either.

I'm looking for a good book which goes over Generics in great detail.
and to have as a reference book on my shelf.

Personal Experience Only, Please.

..

My 1.1 CollectionBase objects look like this most of the time.

I'm trying to determine if I can *always* get the *exact same* functionality
with generics.......

public class CustomerCollection : System.Collections.CollectionBase
{

public void Add ( BusinessObjects.Customer cust )
{
base.InnerList.Add(cust);
}

public BusinessObjects.Customer this[int index]
{
get
{
return (BusinessObjects.Customer )base.InnerList[index];
}
}
public BusinessObjects.Customer Contains( string custId )
{

foreach( BusinessObjects.Customer item in base.InnerList )
if( item.CustomerID .Equals(custId) )
{
return item;
}
return null;
}
public BusinessObjects.Customer Remove(string custId)
{
// remove the object, but also return it.

BusinessObjects.Customer returnObject = null;
returnObject = this.Contains(custId);
if (null != returnObject )
{
base.InnerList.Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(object value)
{
base.OnValidate(value);
if (!(value is BusinessObjects.Customer))
{
throw new ArgumentException("Collection only supports Customer
objects.");
}
}
}


I don't know any book, but in case you're interested, I wrote an
article a while ago
(http://www.coders-lab.dotnetnuke-por.../Default.aspx).
--
Ludwig Stuyck
http://www.coders-lab.be
May 24 '06 #2

That's a nice write up, and you talk about my exact questions.

I'm reading it now.

Thanks for the work, and the link to it.

...

(I'm still taking book recommendations, I like having a reference book on
the shelf sometimes).

"Ludwig" <no**@none.com> wrote in message
news:v8********************************@4ax.com...
On Wed, 24 May 2006 16:25:29 -0400, "sloan" <sl***@ipass.net> wrote:

I'm not the sharpest knife in the drawer, but not a dummy either.

I'm looking for a good book which goes over Generics in great detail.
and to have as a reference book on my shelf.

Personal Experience Only, Please.

..

My 1.1 CollectionBase objects look like this most of the time.

I'm trying to determine if I can *always* get the *exact same* functionalitywith generics.......

public class CustomerCollection : System.Collections.CollectionBase
{

public void Add ( BusinessObjects.Customer cust )
{
base.InnerList.Add(cust);
}

public BusinessObjects.Customer this[int index]
{
get
{
return (BusinessObjects.Customer )base.InnerList[index];
}
}
public BusinessObjects.Customer Contains( string custId )
{

foreach( BusinessObjects.Customer item in base.InnerList )
if( item.CustomerID .Equals(custId) )
{
return item;
}
return null;
}
public BusinessObjects.Customer Remove(string custId)
{
// remove the object, but also return it.

BusinessObjects.Customer returnObject = null;
returnObject = this.Contains(custId);
if (null != returnObject )
{
base.InnerList.Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(object value)
{
base.OnValidate(value);
if (!(value is BusinessObjects.Customer))
{
throw new ArgumentException("Collection only supports Customer
objects.");
}
}
}

I don't know any book, but in case you're interested, I wrote an
article a while ago

(http://www.coders-lab.dotnetnuke-por...icles/tabid/16
942/Default.aspx). --
Ludwig Stuyck
http://www.coders-lab.be

May 24 '06 #3
On Wed, 24 May 2006 17:17:20 -0400, "sloan" <sl***@ipass.net> wrote:

That's a nice write up, and you talk about my exact questions.

I'm reading it now.

Thanks for the work, and the link to it.

..

(I'm still taking book recommendations, I like having a reference book on
the shelf sometimes).


Always interested in feedback, grammatical errors for example, because
English is not my mother tongue. And if you think that something is
missing, please let me know.
--
Ludwig Stuyck
http://www.coders-lab.be
May 24 '06 #4
Why force a download Ludwig? That's not needed and will only cause many
people to go away.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Ludwig" <no**@none.com> wrote in message
news:dv********************************@4ax.com...
On Wed, 24 May 2006 17:17:20 -0400, "sloan" <sl***@ipass.net> wrote:

That's a nice write up, and you talk about my exact questions.

I'm reading it now.

Thanks for the work, and the link to it.

..

(I'm still taking book recommendations, I like having a reference book on
the shelf sometimes).


Always interested in feedback, grammatical errors for example, because
English is not my mother tongue. And if you think that something is
missing, please let me know.
--
Ludwig Stuyck
http://www.coders-lab.be

May 24 '06 #5
_DD
There are books that deal with getting up to speed on new C# 2.0
features, but I know of only one book that deals -only- with Generics.
That's Ted Golding's "Pro .NET 2.0 Generics". See:
http://www.amazon.com/gp/product/0764559885/
May 25 '06 #6
I agree. Besides, it took me couple of seconds to visualize
the button, I even almost gave up and noticed it at the very
last moment before going out of the page.

clintonG wrote:
Why force a download Ludwig? That's not needed and will only cause many
people to go away.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Ludwig" <no**@none.com> wrote in message
news:dv********************************@4ax.com...
On Wed, 24 May 2006 17:17:20 -0400, "sloan" <sl***@ipass.net> wrote:
That's a nice write up, and you talk about my exact questions.

I'm reading it now.

Thanks for the work, and the link to it.

..

(I'm still taking book recommendations, I like having a reference book on
the shelf sometimes).

Always interested in feedback, grammatical errors for example, because
English is not my mother tongue. And if you think that something is
missing, please let me know.
--
Ludwig Stuyck
http://www.coders-lab.be


May 25 '06 #7
On Thu, 25 May 2006 12:33:46 GMT, Sericinus hunter <se*****@flash.net>
wrote:
I agree. Besides, it took me couple of seconds to visualize
the button, I even almost gave up and noticed it at the very
last moment before going out of the page.


Thanks for the feedback. Meanwhile I've created a html version of the
article.

Other feedback I got:
- generics are not only used for collections
- add generics and databinding topic
I'll update the article in a few days with these additions.
--
Ludwig Stuyck
http://www.coders-lab.be
May 26 '06 #8

Lugwig,

I've been converting my 1.1 demo
(http://spaces.msn.com/sholliday/ 5/24/2006 )

I've been using your article/pdf ... and its been very easy with your
examples.

...

For feedback:

Anal Improvement #1
If there was a table of contents with clickable links to stuff like
"Filters", etc, that'd be nice. I did the conversion over a period of 3
days, and I was always text searching to find the right section.

......
Enhanced .Remove method??

Technically, there is one thing I'm trying to do.. and maybe you have
feedback.

The "built in" .Remove method takes an object as the parameter. and returns
a bool ...
Ex:
List<BusinessLayer.BusinessObjects.Customer> custCollection =
GetCollection();//something to get a collection of Customer objects

BusinessLayer.BusinessObjects.Customer custToRemove = custCollection[3]; //
assume 3 or more items in the collection for this illustration

bool itWorked = custCollection.Remove(custToRemove);

Where the .Remove returns a bool .. and the argument a Customer object.

In my 1.1 code .. my .Remove method

#1 I have on .Remove which takes the unique identifier of a Customer
(CustomerId) and then
#2 Uses it to find the Customer object ... then after if finds it... removes
it.
#3 ~~and returns the Customer object back to the caller.

On #3, you'll see that my comments point to the java way of doing a .Remove
........

Not that I'm a super-java lover, but I see the value of doing this
sometimes.

Most times , I don't care about it being removed. On occasion, I may want
to keep track of it .. after I removed it from the Collection.

//Sample Code
public BusinessObjects.Customer Contains( string custId )
{

foreach( BusinessObjects.Customer item in base.InnerList )
if( item.CustomerID .Equals(custId) )
{
return item;
}
return null;
}
public BusinessObjects.Customer Remove(string custId)
{
// see
http://java.sun.com/j2se/1.4.2/docs/...va.lang.Object)
// for java method, which returns the object you removed, in case
// you want to do something with it

BusinessObjects.Customer returnObject = null;
returnObject = this.Contains(custId);
if (null != returnObject )
{
base.InnerList.Remove (returnObject);
}
return returnObject;
}

I guess I'm wondering if there is a way to return the actual Customer object
(that I just removed) back to the caller...
in the Generics world.

I'm working on it now .. to see what I can come up with, but thought I'd
share that nugget with you.

Feel free to comment/critique my method ... you're not going to hurt my
feelings ....

...

Other than that, its been a direct portover.... and I'm becoming more
comfortable with generics, so thanks again for the well laid out article.

...

Sloan

"Ludwig" <no**@none.com> wrote in message
news:vb********************************@4ax.com...
On Thu, 25 May 2006 12:33:46 GMT, Sericinus hunter <se*****@flash.net>
wrote:
I agree. Besides, it took me couple of seconds to visualize
the button, I even almost gave up and noticed it at the very
last moment before going out of the page.


Thanks for the feedback. Meanwhile I've created a html version of the
article.

Other feedback I got:
- generics are not only used for collections
- add generics and databinding topic
I'll update the article in a few days with these additions.
--
Ludwig Stuyck
http://www.coders-lab.be

Jun 2 '06 #9
"sloan" wrote :
I'm looking for a good book which goes over Generics in great detail.
and to have as a reference book on my shelf.
Sloan, these are some on-line resouces for Generics shorty to be publised in
an article on Generic Dictionaries in DeVX.com's website.

Hope they are useful :

1. Books (and free on-line chapters and book) PDF links

Pro C# 2005 and the .NET 2.0 Platform
Andrew Troelsen, APress Publishing, 2005
Chapter 10 : "Understanding Generics" is excellent
available on-line as a free PDF download from Apress at :
http://www.apress.com/ApressCorporat...94193-2965.pdf

Visual C# 2005 : A Developer's Notebook
Jesse Liberty, O'Reilly Publishing,
Chapter 1 : pp. 1~22 : A great exploratory walk-through of Generics in
..NET 2.0 with very
sophisticated code examples. Strong coverage of iterators and enumerators
for Generics.
available on-line as a free PDF download from O'Reilly at :
http://www.oreilly.com/catalog/visua...apter/ch01.pdf

The "Official" ECMA Specification which includes Generics in .NET 2.0 :
Standard ECMA-334 : C# Language Specification 4th. edition (June 2006)
available on-line as a free PDF download from ECMA at :
http://www.ecma-international.org/pu...T/Ecma-334.pdf

2. Selected Links :

On CodeProject.Com : (selected to illustrate range of 'non-obvious' uses
of Generics)

Generic Singleton Pattern using Reflection, in C# by Martin Lapierre
http://www.codeproject.com/cs/design...tonPattern.asp
Uses 'constraint' feature of Generics to create Singleton with
non-accessible constructor.

A Generic Tree Collection by Nicholas Butler
http://www.codeproject.com/csharp/treecollection2.asp
Nice demonstration of how to use serialization with Generic Types, as
well as a very handy generic

Operator Overloading with Generics by Keith Farmer
http://www.codeproject.com/csharp/ge...rs.aspTreeView class
Very interesting code that shows use of Generic classes, delegates.
Mentions that Delegate calling by late-binding is optimized in .NET 2.0,
and has
a link to the MSDN article by Pobar listed below.

Generics, Serialization and NUnit by CraigD.
http://www.codeproject.com/useritems/Kelvin.asp
Using Generics to simplify serialization and de-serialization to Binary
Files. Coverage
of issues using NUnit with Generics.

On MSDN :

Introducing Generics in the CLR by Jason Clark (revised version, MSDN
Magazine, January 2006)
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
A very good overview of Generics in .NET 2.0 including advanced topics.

Performance Pitfalls to Craft Speedy Applications by Joel Pobar, MSDN
Magazine, July 2005
http://msdn.microsoft.com/msdnmag/is...n/default.aspx
Interesting (and technically deep article) on reflection in .NET 2.0 and
calling speed.
Excellent section explaining 'rules and 'constraints features of
Generics.
Jul 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jon Slaughter | last post by:
I'm reading Alexandrescu's Modern C++ design about the concept of policies. What I'm wondering is if policies are a common design pattern in C++(OOP) nowdays? It seems like a good idea but I'm...
27
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and...
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
13
by: Ludwig | last post by:
Hi, I wrote an article about generics in C# 2.0; you can download it at http://www.coders-lab.be/Technical%20documents/CTG_Articles_Generics.pdf Suggestions and feedback always very welcome, kind...
3
by: Wiktor Zychla [C# MVP] | last post by:
since generics allow us to implement several IEnumerable<T> interfaces on a single class, I think that "foreach" should somehow reflect that. suppose we have a enumerable class class C :...
11
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
5
by: clintonG | last post by:
I have to master these relatively new constructs. I'm looking around and asking you too for your suggested learning resource(s).
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.