views:

354

answers:

4
string s = new string("Hello World").Replace(" ","_").ToLower().ToUpper();

So you basically return from each method the modified object so can you call new methods on it.

+25  A: 

Method chaining. (Wikipedia)

Boldewyn
Too quick for me :)
Space_C0wb0y
@Space_C0wb0y: Was sheer luck. @teedyay: Thanks for the typo correction.
Boldewyn
Faster gun than a @space cowboy. That's badass!
DrDro
A: 

Equivenlant to:

string s = new string("Hello World");
s = s.Replace(" ","_");
s = s.ToLower();
s = s.ToUpper();
BG100
Actually, just reread your question.... not really the answer your looking for!!
BG100
That won't compile without some more semicolons.
James Kolpack
@James: Fixed!!
BG100
+17  A: 

Or Fluent Interface

Andrey
+1. Haven't heard that name before.
Boldewyn
You might say that the objects have a Fluent Interface but the pattern quoted is using chaining?
Neil Trodden
+3  A: 

The answer is provided by Boldewyn, I am just writing this as a suggestion.

When chaining methods like this, try to write it as follows -

string s = new string("Hello World")
               .Replace(" ","_")
               .ToLower()
               .ToUpper();

This improves code readability.

Night Shade
Application wise, is this not the way UI Automation code is written ?
Icarus