Passing a single item as IEnumerable<T>

Well, if the method expects an IEnumerable you've got to pass something that is a list, even if it contains one element only.

passing

new[] { item }

as the argument should be enough I think


In C# 3.0 you can utilize the System.Linq.Enumerable class:

// using System.Linq

Enumerable.Repeat(item, 1);

This will create a new IEnumerable that only contains your item.


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.