Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:46:17+00:00 2026-06-15T14:46:17+00:00

Consider this List<string> List<string> data = new List<string>(); data.Add(Text1); data.Add(Text2); data.Add(Text3); data.Add(Text4); The problem

  • 0

Consider this List<string>

List<string> data = new List<string>();
data.Add("Text1");
data.Add("Text2");
data.Add("Text3");
data.Add("Text4");

The problem I had was: how can I get every combination of a subset of the list?
Kinda like this:

#Subset Dimension 4
Text1;Text2;Text3;Text4

#Subset Dimension 3
Text1;Text2;Text3;
Text1;Text2;Text4;
Text1;Text3;Text4;
Text2;Text3;Text4;

#Subset Dimension 2
Text1;Text2;
Text1;Text3;
Text1;Text4;
Text2;Text3;
Text2;Text4;

#Subset Dimension 1
Text1;
Text2;
Text3;
Text4;

I came up with a decent solution which a think is worth to share here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:46:18+00:00Added an answer on June 15, 2026 at 2:46 pm

    I think, the answers in this question need some performance tests. I’ll give it a go. It is community wiki, feel free to update it.

    void PerfTest()
    {
        var list = Enumerable.Range(0, 21).ToList();
    
        var t1 = GetDurationInMs(list.SubSets_LB);
        var t2 = GetDurationInMs(list.SubSets_Jodrell2);
        var t3 = GetDurationInMs(() => list.CalcCombinations(20));
    
        Console.WriteLine("{0}\n{1}\n{2}", t1, t2, t3);
    }
    
    long GetDurationInMs(Func<IEnumerable<IEnumerable<int>>> fxn)
    {
        fxn(); //JIT???
        var count = 0;
    
        var sw = Stopwatch.StartNew();
        foreach (var ss in fxn())
        {
            count = ss.Sum();
        }
        return sw.ElapsedMilliseconds;
    }
    

    OUTPUT:

    1281
    1604 (_Jodrell not _Jodrell2)
    6817
    

    Jodrell’s Update

    I’ve built in release mode, i.e. optimizations on. When I run via Visual Studio I don’t get a consistent bias between 1 or 2, but after repeated runs LB’s answer wins, I get answers approaching something like,

    1190
    1260
    more
    

    but if I run the test harness from the command line, not via Visual Studio, I get results more like this

    987
    879
    still more
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: static void Main(string[] args) { var persons = new List<Person> {
Consider this code: public <T> List<T> meth(List<?> type) { System.out.println(type); // 1 return new
Consider the following criteria query: var x = SomeCriteria.AddOrder(new Order(Name, true)).List(); This will order
Consider this class: public class Column<T> { public string Header { get; set; }
Consider this short python list of dictionaries (first dictionary item is a string, second
Consider the following problem: given a list of length three of tuples (String,Int), is
Consider this query to group a list of students by the 1st letter of
Consider this Python code for printing a list of comma separated values for element
consider this simple function def foo(l=[]): if not l: print List is empty else
Please consider this site . I'm having trouble stretching the submenu list items in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.