473,394 Members | 1,845 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,394 software developers and data experts.

CollectionBase Item Member Access

Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #1
6 1819
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #2
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #3
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #4
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #5
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fileInt;
else
dRow = ((CookieRow)r).cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #6
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fileInt;
else
dRow = ((CookieRow)r).cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #7

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

Similar topics

2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
0
by: DelGator | last post by:
Foundation...Accessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class. How would you access the derived class members...
3
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
1
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties...
8
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.