I'd like to be able to write the following code:
// contains 500 entries
IList<string> longListOfStrings = ...
// shorterListsOfStrings is now an array of 5 IList<string>,
// with each element containing 100 strings
IList<string>[] shorterListsOfStrings = longListOfStrings.Split(5);
To do this I have to create a generic extension method called Split
that looks something like the following:
public static TList[] Split<TList>(this TList source, int elementCount)
where TList : IList<>, ICollection<>, IEnumerable<>, IList, ICollection, IEnumerable
{
return null;
}
But when I try to compile that, the compiler tells me that IList<>
, ICollection<>
and IEnumerable<>
require a type argument. So, I changed the definition to the following:
public static TList<TType>[] Split<TList<TType>>(this TList<TType> source, int elementCount)
where TList : IList<TType>, ICollection<TType>, IEnumerable<TType>, IList, ICollection, IEnumerable
{
return null;
}
but then the compiler complains that it can't find type TList
. I have an idea that I'm overcomplicating things but I can't see how... any help is appreciated!