473,756 Members | 4,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CustomerCollect ion : System.Collecti ons.CollectionB ase
{

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

public BusinessObjects .Customer this[int index]
{
get
{
return (BusinessObject s.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(c ustId);
if (null != returnObject )
{
base.InnerList. Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(obje ct value)
{
base.OnValidate (value);
if (!(value is BusinessObjects .Customer))
{
throw new ArgumentExcepti on("Collection only supports Customer
objects.");
}
}
}
May 24 '06 #1
9 5985
On Wed, 24 May 2006 16:25:29 -0400, "sloan" <sl***@ipass.ne t> 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 CustomerCollect ion : System.Collecti ons.CollectionB ase
{

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

public BusinessObjects .Customer this[int index]
{
get
{
return (BusinessObject s.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(c ustId);
if (null != returnObject )
{
base.InnerList. Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(obje ct value)
{
base.OnValidate (value);
if (!(value is BusinessObjects .Customer))
{
throw new ArgumentExcepti on("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.co m> wrote in message
news:v8******** *************** *********@4ax.c om...
On Wed, 24 May 2006 16:25:29 -0400, "sloan" <sl***@ipass.ne t> 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 CustomerCollect ion : System.Collecti ons.CollectionB ase
{

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

public BusinessObjects .Customer this[int index]
{
get
{
return (BusinessObject s.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(c ustId);
if (null != returnObject )
{
base.InnerList. Remove (returnObject);
}
return returnObject;
}
protected override void OnValidate(obje ct value)
{
base.OnValidate (value);
if (!(value is BusinessObjects .Customer))
{
throw new ArgumentExcepti on("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.ne t> 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.co m> wrote in message
news:dv******** *************** *********@4ax.c om...
On Wed, 24 May 2006 17:17:20 -0400, "sloan" <sl***@ipass.ne t> 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.co m> wrote in message
news:dv******** *************** *********@4ax.c om...
On Wed, 24 May 2006 17:17:20 -0400, "sloan" <sl***@ipass.ne t> 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<BusinessLa yer.BusinessObj ects.Customer> custCollection =
GetCollection() ;//something to get a collection of Customer objects

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

bool itWorked = custCollection. Remove(custToRe move);

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(c ustId);
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.co m> wrote in message
news:vb******** *************** *********@4ax.c om...
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 : "Understand ing 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
1898
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 having a little trouble following along and I'm wondering if I should put in the time to really understand it or if its just a waste because there are better things out there. Like all these things about traits, generics, policies, etc don't mean...
27
2461
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 still no can do... Any info would be great!
23
2548
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 vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2744
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 it defines the language more completely. Great to use.
13
1835
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 regards, Ludwig --
3
1663
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 : IEnumerable, IEnumerable<int>, IEnumerable<string> { ... we are allowed to enumerate IEnumerable: foreach ( object item in o ) ...
11
2501
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 provide an implemation of the operator +. Now I want to write another generic class Plan<DType>, which can
13
3836
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 application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
5
1515
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
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.