S
Steve Thackery
I'm teaching myself C# using "C# in easy steps" by Tim Anderson, which seems
pretty good for a complete newbie.
But I'm puzzled by this piece of example code:
string theColor = textBox1.Text.Trim().ToUpper();
My understanding of textBox1.Text is that textBox1 is an object, and Text is
a property of that object. This seems straightforward so far. I also
appreciate that textBox1 has a number of methods, too, such as Dispose, so
that I could write:
textBox1.Dispose.
But Trim() is obviously a method, and the way it's written suggests that the
Text property has a Trim() method.
But how can a property (Text) have its own method? I thought methods and
properties both belonged to classes.
Is .Text actually an object, hidden away inside textBox1 and pretending to
be a property? Perhaps I could get may brain around that, but.....
Even more confusing for me is ToUpper(). This seems to belong to the Trim()
method, so one method has another method. Totally confusing!
I thought the '.' notation was only used in a hierarchical way, such as:
form.control.method
or
namespace.form.control.property
The quoted example seems to be:
control.property.method.method
....which makes no sense to me at all. Or is it just a free-for-all and I
can string as many methods in a row as I like:
control.property.method.method.method.etc....
If so, does the order matter?
I must be missing something really obvious about the '.' notation. Can
anyone illuminate me?
Many thanks!
SteveT
pretty good for a complete newbie.
But I'm puzzled by this piece of example code:
string theColor = textBox1.Text.Trim().ToUpper();
My understanding of textBox1.Text is that textBox1 is an object, and Text is
a property of that object. This seems straightforward so far. I also
appreciate that textBox1 has a number of methods, too, such as Dispose, so
that I could write:
textBox1.Dispose.
But Trim() is obviously a method, and the way it's written suggests that the
Text property has a Trim() method.
But how can a property (Text) have its own method? I thought methods and
properties both belonged to classes.
Is .Text actually an object, hidden away inside textBox1 and pretending to
be a property? Perhaps I could get may brain around that, but.....
Even more confusing for me is ToUpper(). This seems to belong to the Trim()
method, so one method has another method. Totally confusing!
I thought the '.' notation was only used in a hierarchical way, such as:
form.control.method
or
namespace.form.control.property
The quoted example seems to be:
control.property.method.method
....which makes no sense to me at all. Or is it just a free-for-all and I
can string as many methods in a row as I like:
control.property.method.method.method.etc....
If so, does the order matter?
I must be missing something really obvious about the '.' notation. Can
anyone illuminate me?
Many thanks!
SteveT