Blog » Method Chaining of Objects in C#

Method Chaining of Objects in C#

I’m sure that many of you c# programmers know this already but I’m posting this here more as a way to reinforce this in my own brain as I seem to forget this…
When you have an object that you want to apply a number of methods to, the order of processing will always be from the inside out.
For example:
String.Format("[{0}]", name.Trim().Replace("\"", string.Empty)); will return [Deborah ] while
String.Format("[{0}]", name.Replace("\"", string.Empty).Trim()); will return is [Deborah].

So there you have it!

Michael Gibbs
Stalk Me...
Latest posts by Michael Gibbs (see all)