I don’t know what your system is. A class, a method, a framework?
A method can return several results through out
parameters
public void CheckEntities(Entity a, Entity b, out bool isAOK, out bool isBOK)
{
isAOK = Test(a);
isBOK = Test(b);
}
You can also create a dedicated type
public class EntitiesStatus
{
public EntitiesStatus(bool isAOK, bool isBOK)
{
IsEntity1OK = isAOK;
IsEntity2OK = isBOK;
}
IsEntity1OK { get; private set; }
IsEntity2OK { get; private set; }
}
You can use an enum
[Flags]
public enum EntityStatus
{
NoneIsOK = 0,
FirstIsOK = 1, // = 2^0
SecondIsOK = 2, // = 2^1
BothAreOK = FirstIsOK | SecondIsOK;
}
When using the FlagsAttribute
, make sure that the enum constants the can be combined are all powers of two. This ensures that any combination of them yields distinct values.
You have a lot of options, but don't use some "magic" bit manipulations that make look your code like early days c code and requires extra knowledge from those using your char
result. And by the way, why char
? Even just using an int
and constants would be better (while not optimal). const int FirstIsOK = 1, SecondIsOK = 2; int result FirstIsOK + SecondIsOK;
. This requires no bit manipulations.