What's the best name for a non-mutating “add” method on an immutable collection?

前端 未结 30 1296
夕颜
夕颜 2020-11-29 16:47

Sorry for the waffly title - if I could come up with a concise title, I wouldn\'t have to ask the question.

Suppose I have an immutable list type. It has an operat

30条回答
  •  生来不讨喜
    2020-11-29 17:17

    I would call it Extend() or maybe ExtendWith() if you feel like really verbose.

    Extends means adding something to something else without changing it. I think this is very relevant terminology in C# since this is similar to the concept of extension methods - they "add" a new method to a class without "touching" the class itself.

    Otherwise, if you really want to emphasize that you don't modify the original object at all, using some prefix like Get- looks like unavoidable to me.

提交回复
热议问题