Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Can you create a list based on the output of bools from another class?

Edited for (hopefully clarity):

What I am looking to do (and not sure if it can be done) is in this order:

  1. Determine if variables are/are not present (eg, "Do you have a mouse? Do you have a keyboard? Do you have Speakers? etc.)
  2. Using the output from #1, create a list that incorporates the outputs from the are/are not statement (eg, Do you have a mouse? Yes? Okay Add mouse to the list. Do you have a keyboard? No? Okay, omit the keyboard from the same list as the mouse and do not add it to another list. Do you have speakers? Yes? Add speakers to the same list that the mouse is in.
  3. Be able to reference this list at a later point.

If the code below confuses you, please don't let it and instead look at #1-3 instead.

Edit2: This is for C# w/ Target Framework .NET Framework 4.7.2, Output type Class Library(.dll), in case that changes how the code needs to be written.

public class AreFooPresent
{
     public static bool foo0 = false
     public static bool foo1 = false
     public static bool foo2 = false
}

public class AreTheyThereList
    {
        List<FooList> myList = new List<FooList>
        {
            myList.Add(new FooList(if return foo0 != false));
            myList.Add(new FooList(if return foo1 != false));
            myList.Add(new FooList(if return foo2 != false));
        }
    }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Another one using linq

using System.Linq;
...
var list = (new bool[] {AreFooPresent.foo0, AreFooPresent.foo1, AreFooPresent.foo2})
    .Where(b => b).ToList();

And I see you initializing some object FooList, in this case something like

using System.Linq;
...
var list = (new bool[] {AreFooPresent.foo0, AreFooPresent.foo1, AreFooPresent.foo2})
    .Where(b => b)
    .Select(b => new FooList(b)).ToList();
over 4 years ago · Santiago Trujillo Report

0

welcome to SO! Something simple like the code below does the job. It'll only add to the list IF it's true and as they're static members, you can reference the class then the static members.

Then at the end, it'll return the list of positive bools (if any) - if not, it'll be an empty list.

    public class AreFooPresent 
    {
      public static bool foo0 = false
      public static bool foo1 = false
      public static bool foo2 = false
    }
    
    public class AreTheyThereList 
    {
      public List<bool> MyPositiveFooCollectionMethod() 
      {
        List<bool>myList = new List<FooList>();
    
        if (AreFooPresent.foo0) myList.Add(AreFooPresent.foo0);
        if (AreFooPresent.foo1) myList.Add(AreFooPresent.foo1);
        if (AreFooPresent.foo2) myList.Add(AreFooPresent.foo2);
    
        return myList;
      }
    }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!