0
string "hello world".toLower().toUpper().replace("o", "x");

How do I make my own class be able to have extension methods like string in the example above? Maybe not that usefull, but I just cant figure out how to do it

Half_Baked
  • 340
  • 4
  • 18

1 Answers1

6

These are called chained methods that can be used for fluent APIs.

One normally creates them by returning the same type from all method calls.

See Tips for writing fluent interfaces in C# 3.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009