The options you have are
return default(T)
which will be ambiguous, as this may be a valid list item.
Or you can return something like -1 , as you said, but this is quite related to your code.
Or you can return null , but this can only be done if T is a type with a null value.
In all previous cases, if the caller does not know about this situation, the application may continue with an invalid value, which will lead to unknown consequences .
Therefore, probably the best option is to throw an exception:
throw new InvalidOperationException();
With this approach, you quickly execute , and make sure that nothing happens unexpectedly beyond the intentions of the caller.
Another reason to back up this option. Take, for example, the Linq extension methods. If you call First() , Single() or Last() on an empty list, you will receive an InvalidOperationException message with the message "The sequence contains no elements." Providing your class with behavior similar to rum classes is always good.
I add a side note thanks to Alexey Levenkov's comment in the question. This random generation is not the best approach. Take a look at this question .
Second note. You declare your function as an extension method for IList<T> (you do this with this to the first parameter), but then you name it as a static helper method. The extension method is syntactic sugar, which instead:
foo = Utilites.PickRandom(myList);
allows you to do this:
foo = myList.PickRandom();
More on extension methods can be found here .