I need to create a method Package<T>
that, given a sequence of interfaces of type T
, an int n
and a T default
, put the elements of the sequence in n+1 blocks, so that i can invoke a method on the first element(that is a interface) of every block and use the inner elements of the other n interfaces of each block as parameters of that method. If there's a block without enough parameters to be used, then the default
must be used to full the block.
Let's do an example with integers. Suppose i've got an interface IMyInterface<int>
that uses the sum as the method to be invoked. s is the sequence of twelve IMyInterfaces, each one containing respectively one of the first 12 integers, starting from 0 (so [0-11]). The other arguments of my Package method are n=3 and default=20.
Then what i'm expecting is a list of 3 integers: 6 (that is = 0+1+2+3), 22(that is = 4+5+6+7), 38(that is = 8+9+10+11). (default is not used).
If n==4 it changes and i expect a list of 3 integers: 10 (0+1+2+3+4), 35(5+6+7+8+9), 81(10+11+20+20+20) (here default is used to fill the three remainig integers of last block).
Here's the method:
IEnumerable <T> Package <T >( IEnumerable < IMyInterface<T>> sequence , int n, T default )
and here's the interface:
public interface IMyInterface <T>
{
T MergeWith ( params T[] others );
T InnerElem { get; }
}
I hope this explanation is enough to understand my question.