View Single Post
  #5 (permalink)  
Old August 25th, 2010, 12:57 PM
chroniclemaster1 chroniclemaster1 is offline
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by samjudson View Post
It may be that you simply remove the " = new ContentType()" from the variable declaration.
:) Got it! I'm no longer simply a consumer of generics, I'm now an author. The string problem was exactly what you pointed out Sam. Since the variable is an open generic type, I can't initialize it (like consuming an interface). Once I dropped the initialization "ContentType classTableCellContent;" that problem went away.

Quote:
Originally Posted by sridhar c View Post
Hi Chroniclemaster1, There is an error your code, which throws cannot implicitly convert type ContentType to ContentType ....
Just remove the '<ContentType>' content in addContent method and should compile fine.
Then sridhar c's fix solved my problem with the second type declaration. Now I only declare one open data type so the function is talking the same set of variable names as the class. :D

Quote:
Originally Posted by samjudson View Post
Also, it is convention to use "T" as the name of the generic type - this is much shorter and easier to read, and also makes it easier to spot where the generic type is used. ContentType could quite easily be the name of an actual class.
:) I tried changing the names on my variable types several times during testing so "ContentType" was simply the last one I'd used. I've now changed it back to my preferred TContent (using a T prefix like the very sensible "I" prefix used for interfaces). I like T because it clearly stands for type, but the typical usage for multiple types (T, U, V) seems a bit silly to me since U and V are only weakly related to the idea of type (their letters are adjacent to T which stands for type). I also have to waste brain space remembering that this T and U in one function are totally unrelated to T and U in another function / class. Using interface style naming with a T prefix like TContent greatly reduces naming collisions. This isn't entirely customary but the consistent use of T (and the variables appearance in brackets <TContent>) still make it clear for anyone that these are open generic type names. So that's what I actually use and why I prefer it.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.