Re: Newbie Q: Explain: string Name = dept.FindChairperson().Name
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Tue, 05 Jun 2007 05:55:15 -0700
On Jun 5, 1:50 pm, Rex <RexForum4...@xxxxxxxxxxxxxxxxxx> wrote:
Quick newbie question: I am NOT looking for some code solution - I am
simply looking for an explanation. In a passing bit of code in a C#
book I have, I saw the following line:
string Name = dept.FindChairperson().Name
I AM pretty much getting C# and its various syntaxes, but I had not
seen this before. Here's my question: It is clear that
"FindChairperson" is a method within the dept object. But then
how is ".Name" somehow subservient to the method? In other words,
I think of a class as having methods and properties... but how is it
that they are somehow COMBINED here?
Okay: dept is a variable, of some type that has a FindChairperson()
method. The return type of the FindChairperson method then has a Name
property. So FindChairperson() might be declared as something like:
Person FindChairperson()
where Person has a Name property.
So your original expression calls FindChairperson and then uses the
Name property of the Person returned by that method.
(I'm deliberately ignoring the fact that it's probably a reference
which is returned, etc, in order to keep things simple.)
Jon
.
- References:
- Prev by Date: Re: Newbie Q: Explain: string Name = dept.FindChairperson().Name
- Next by Date: Re: String builder
- Previous by thread: Re: Newbie Q: Explain: string Name = dept.FindChairperson().Name
- Next by thread: Re: Newbie Q: Explain: string Name = dept.FindChairperson().Name
- Index(es):