We give the following examples:
string amountDisplay = presentation.Amount == 1 ? "" : String.Format("{0} x ", presentation.Amount);
In any case, use String.Format so that it is formatted depending on the properties without having to fulfill the condition of the "value" of the parameters?
another use case:
String.Format("({0}) {1}-{2}", countryCode, areaCode, phonenumber);
If I have only a phone number, I will get something like "() -5555555", which is undesirable.
another use case:
String.Format("my {0} has {1} cat[s]", "Aunt", 3)
in this case, I would like to include s in [] if the value is> 1, for example.
Is there any black String.Format syntax that removes parts of the code depending on the value of the parameters or null?
Thank.
source
share