这种模式叫什么?

时间:2010-09-23 10:11:31

标签: design-patterns

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

所以你基本上从每个方法返回修改过的对象,所以你可以在它上面调用新的方法。

4 个答案:

答案 0 :(得分:27)

方法链接。 (Wikipedia

答案 1 :(得分:18)

答案 2 :(得分:4)

答案由Boldewyn提供,我只是将此作为建议。

链接这样的方法时,请尝试按如下方式编写 -

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

这提高了代码的可读性。

答案 3 :(得分:0)

相当于:

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