Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inheritance question 2

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
US
I'm probably a beginner to intermediate c# programmer.

I have a question about inheritance.

I know that

newclass : baseclass is simple inheritance, but if the person types:


newclass : baseclass<someotherclass>


what is that someotherclass, or rather what are they doing there?
 
baseclass is most likely a Generic Collection made up of objects of the someotherclass type

Rhys

"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
Terry Pratchett
 
And are those inherited as well? what does putting that someotherclass in between <> do?
 
generic objects are stongly typed. the simplist example is IList<T>. it has methods like
.Add(T item)
.Remove(T item)
.Contains(T item)

if you define IList<int> = new List<int>();
then the functions read:
.Add(int item)
.Remove(int item)
.Contains(int item)

if you define IList<someotherclass> = new List<someotherclass>();
then the functions read:
.Add(someotherclass item)
.Remove(someotherclass item)
.Contains(someotherclass item)

the same is true for your basecalss<> object.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
newclass : baseclass<someotherclass> is a combination between simple inheritance and compile-time inheritance.

Compile-time inheritance is when you have a class Container<T> and you're declaring an object like Container<int> anIntContainer = new Container<int>(...); That is referred to as "compile-time inheritance" if I am not mistaking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top