Sounds suspiciously like a homework assignment....
Since I presume the size is variable, you'll want to use recursion. Something like:
static void Main(string[] args)
{
int[] originalList = new int[] { 1, 2, 3, 4 };
Stack<int> currentList = new Stack<int>();
List<int[]> listOfSubsets = new List<int[]>();
BuildListOfSubsets(originalList, listOfSubsets, 3, 0, currentList);
}
private static void BuildListOfSubsets(int[] originalList, List<int[]> listOfSubsets, int sizeOfSubsetList, int currentLevel, Stack<int> currentList)
{
if (currentList.Count == sizeOfSubsetList)
{
int[] copy = new int[sizeOfSubsetList];
currentList.CopyTo(copy, 0);
listOfSubsets.Add(copy);
}
else
for (int ix = currentLevel; ix < originalList.Length; ix++)
{
currentList.Push(originalList[ix]);
BuildListOfSubsets(originalList, listOfSubsets, sizeOfSubsetList, ix + 1, currentList);
currentList.Pop();
}
}
The result will be in the listOfSubsets list. See if you can find an optimization to leave the for loop early.