This will be a bit more code, but please give the following a try:
new Func(() => {
const int TemperatureLimit = 85;
var FormatTemp = new Func((string tempString) => {
if (string.IsNullOrEmpty(tempString) || tempString == "0")
return "";
else
return (Convert.ToInt32(tempString) >= TemperatureLimit ? "" + tempString + "": tempString);
});
return "Chip: " + FormatTemp(stats.ChipTemp1) + "/" + FormatTemp(stats.ChipTemp2) + "/" + FormatTemp(stats.ChipTemp3) + "/" + FormatTemp(stats.ChipTemp4) + " °C";
})()
Hi, Patrick
Thank you so much!
but there was one nuance that the "/" sign at the end, in the end I get the following
Another way to do it is like below, where we only add the non-zero entries to a list and the put a slash between each element in the list.
new Func(() => {
const int TemperatureLimit = 85;
List tempList = new List();
var AddTemp = new Action((string tempString) => {
if (!string.IsNullOrEmpty(tempString) && tempString != "0")
tempList.Add(Convert.ToInt32(tempString) >= TemperatureLimit ? "" + tempString + "": tempString);
});
AddTemp(stats.ChipTemp1);
AddTemp(stats.ChipTemp2);
AddTemp(stats.ChipTemp3);
AddTemp(stats.ChipTemp4);
return "Chip: " + string.Join("/", tempList) + " °C";
})()