newbee confused with [] and ()

  • Thread starter Thread starter Raymond Du
  • Start date Start date
R

Raymond Du

Hi,

I am confused about when to use bracket and parenthesis, say the following
code snippet:

for (int i=0; i< Request.Form.Count; i++)
Label1.Text = Label1.Text + Request.Form.GetKey(i) + " ";

will give me all names of elements in a form, however to get element's
values I have to do:

for (int i=0; i< Request.Form.Count; i++)
Label1.Text = Label1.Text + Request.Form + " ";

Both Request.Form.GetKey and Request.Form returns a String from a
collection, why the difference in syntax?

TIA
 
Raymond Du said:
I am confused about when to use bracket and parenthesis, say the following
code snippet:

for (int i=0; i< Request.Form.Count; i++)
Label1.Text = Label1.Text + Request.Form.GetKey(i) + " ";

will give me all names of elements in a form, however to get element's
values I have to do:

for (int i=0; i< Request.Form.Count; i++)
Label1.Text = Label1.Text + Request.Form + " ";

Both Request.Form.GetKey and Request.Form returns a String from a
collection, why the difference in syntax?


[] is for indexing - either array indexing or an indexer such as
ArrayList provides.

() is for method calls.
 
Back
Top