Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Smalltalk supports a syntax feature called "message cascades". Cascades are being adopted by the Dart Programming language.

As far as I know, C# doesn't support this. Were they ever considered during the design of the language? Is it conceivable that they could appear in a future version of the language?

share|improve this question
look at LinQ, is that what u look for? – Yusubov Jul 15 '12 at 2:47
Notice also that cascade methods are very useful in Smalltalk because if there is no explicit return in a method, a method answers 'self', therefore, cascading is easier. – user59354 Jul 15 '12 at 20:22

1 Answer 1

Fluent interfaces are easily supported in C# by using return this.

In Linq, extension methods are used to accomplish the same thing. Extension methods over IQueryable or IEnumerable are easily chained together.

Cascades, as described by the page at the link you provided, seem to be merely a subtle refinement of an ordinary Fluent Interface where return this is not required to make it work, as all method calls beginning with .. refer to the first returned result:

    ..text = 'Click Me!'

Does C# support this? No, not exactly. But you can still write the following equivalent code:

var result = query('#my-form').query('button')
result.text = 'Click Me!'

and it is only slightly more verbose (and arguably easier to read).

As to the question, "Were they ever considered for C#," you would have to ask Anders Hejlsberg or Eric Lippert about that. My guess is that they view it as syntactic sugar, which in fact it is.

share|improve this answer
The point is that you can re-use the methods in other contexts where you might need the return value. This makes sense when getters and setters are in fact the same method (i.e. a setter returns the old value and sets the argument, if given). This of course doesn’t fit idiomatic C# code anyway. – Konrad Rudolph Jul 16 '12 at 6:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.