Add value to string

Hello everyone,
I want to add values to strings, but it has to be versatile and short.
Iwant too do something like:

If x is true, add 1 to string

If y is true, add 2 to string

If z is true, add 3 to string

So if all these returned true, I would have something like: 123

If x and z returned true, I would have 13

etc.

Does anyone know how I could do this in as short of a code as I can? Thank you all. (I am using c#)

The shortest and easiest (but probably not most flexible) would be just plainly do that:

private string Whatever(bool x, bool y, bool z)
{
    StringBuilder str = new StringBuilder();
    if (x) str.Append('1');
    if (y) str.Append('2');
    if (z) str.Append('3');
    return str.ToString();
}

You could also use string instead of the StringBuilder, but that would create more instances (up to 4) of string since string is immutable. Depending on how often you will call that it’s not a problem though.

If this is not what you are looking for, you might want to give me a more specific example of what you actually want to do - like, how you get your x/y/z data or what you want to add to the string.