Edited for (hopefully clarity):
What I am looking to do (and not sure if it can be done) is in this order:
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));
}
}
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();
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;
}
}