namespace SubsetsOfSet { using System; using System.Collections.Generic; using System.Linq; class SubsetsOfSet { static void Main() { int[] nums = { 0, 1, 2 }; string[] fruits = {"apple", "peach", "starwberry"}; int b = nums.Length; int n = (int)Math.Pow(2, b); for (int num = 0; num < n; num++) { var subSet = new List<int>(); for (int bit = 0; bit <= b; bit++) { if ((num >> bit & 1) == 1) { subSet.Add(nums[bit]); } } Console.WriteLine("{{{0}}}", string.Join(", ", subSet.Select(i => fruits[i]))); } } } }