且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将单个项目作为 IEnumerable 传递;

更新时间:2023-02-14 11:31:56

你的辅助方法是最干净的方法,IMO.如果您传入一个列表或一个数组,那么一段不道德的代码可能会对其进行转换并更改内容,从而在某些情况下导致奇怪的行为.您可以使用只读集合,但这可能涉及更多的包装.我认为您的解决方案非常简洁.

Your helper method is the cleanest way to do it, IMO. If you pass in a list or an array, then an unscrupulous piece of code could cast it and change the contents, leading to odd behaviour in some situations. You could use a read-only collection, but that's likely to involve even more wrapping. I think your solution is as neat as it gets.