If you are looking for a LINQ solution, try this:
int[] originalList = { 1,2,1 };
var srcl = originalList.ToList();
List<List<int>> ans = Enumerable.Range(0, srcl.Count).SelectMany(start => Enumerable.Range(1, srcl.Count - start).Select(count => srcl.GetRange(start, count))).ToList();
If you are looking for a simpler solution, without Recursion, then this will help:
(This is a common solution to print all the subsets, to print specific scenarios, like having only subsets with length as 3, use the innermost loop)
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5 };
int length = arr.Length;
for (int start = 0; start < length; start++)
{
for (int end = start; end < length; end++)
{
Console.Write("{");
// printing the subset, use this to add any condition,
// like create a array and match the length, or anything
for (int print = start; print <= end; print++)
{
Console.Write(arr[print]);
}
Console.WriteLine("}");
}
}
}
}