'object' does not contain a definition for 'MyArrayList'

D

Daisy

I've got a class that contains a few public properties, and a public
ArrayList called Messages. The ArrayList will store other instances of this
class (thus, creating a tree).

My constructor takes 2 strings that just set properties on the class.

Adding a new Message into the ArrayList of another Message works fine:

this.Data.Messages.Add(new Message("Danny", "Something"));

But then, when I try to add a Message to that Message, eg.

this.Data.Messages[0].Messages.Add(new Message("Danny", "Something"));

I get:

error CS0117: 'object' does not contain a definition for 'Messages'

I know I'm being lazy and should probably cast it to a Message, and then try
access the Messages ArrayList of that object, but putting it in one line
like that, meant I didn't have to have a reference to an object I'm not
really using (isn't that more efficient?).
 
D

Daisy

<snip>

Oops, seems I can do it with brackets:

((Message) this.Data.Messages[0]).Messages.Add(new Message("Danny",
"Something"));

:blush:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top