Can a C# method chain be “too long”?

前端 未结 4 2085
青春惊慌失措
青春惊慌失措 2021-02-05 05:57

Not in terms of readability, naturally, since you can always arrange the separate methods into separate lines. Rather, is it dangerous, for any reason, to chain an excessively l

4条回答
  •  梦毁少年i
    2021-02-05 06:51

    The only consern you should consider regarding this (if yor ignoring readability) is resource handling and GC.. Questions you should ask are.

    • Are the calls I am making returning objects that should be disposed of?
    • am I initing alot of stuff inside a single scope rather than smaller scopes that GC might be more reactive to? (GC is scheduled to run each time you leave a scope, though scheduling and when it actually runs are two different things :-p).

    But really.. weather you call one method per line, or string them all togeather its all ends up being the same in IL (or very nearly the same).

    Josh

提交回复
热议问题