assuming that object from arraylist is button ??

  • Thread starter Thread starter Grisha0
  • Start date Start date
G

Grisha0

hi,
Code:
System.Collections.ArrayList a = new ArrayList();
Button b = new Button();
b.Top= 40;
b.Left= 30;
b.Parent= this;
b.Text ="blah blah blah";
a.Add(b);
b.Text= (Button)a[0].text;
\c\Form1.cs(124): 'object' does not contain a definition for 'text'

how to tell the compiler that this is button ... and get the value from
it...
help please ...
 
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
 
Peter said:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...
 
In that case, some extra brackets should solve your problem. You want
the Text property AFTER you have cast the object to a button. And after
all, brackets are free :-)

b.Text= ((Button)a[0]).Text;
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
 
Grisha0 said:
Peter said:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...
found it :D

was : b.Text = (Button)a[0].Text;
should be: b.Text = ((Button)a[0]).Text;
 
Grisha0 said:
Peter said:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...

(Button)a[0].Text is the same as: (Button)(a[0].Text)
ie. it typecasts the Text property of Object, if that existed, but it
doesn't, hence the error.
 
Back
Top