Lets say i have a method:
UpdateObject(IList<MyObject> objs)
and i want to use that method for sending just one object? (i prefer not using method overloading cause i dont want a lot of methods to handle in my interface)
is there a way i could use the same method without doing the following:
UpdateObject(new List<MyObject>(){singleObj})
Maybe you could pass an
IEnumerable<MyObject>to that method instead.Probably the easiest way to append a single element to an
IEnumerable<T>is to use thisAsIEnumerableextension (although Eric Lippert advises against creating extension for objects):Now you can use everything as
IEnumerable.