"We have an old codebase where strings are used as a swiss army knife," writes Jimmi Hested, "almost everything that goes in or out of a function is ends with a .ToString(), even it's already a string... and sometimes even if it already ends with .ToString()."
"Here is a bit of code from our web front-end. Not only is there a try/catch (just to make sure everything works), but the original developer felt a string was way better than a bool."
try { // Check that a valid scheme has been selected if (scheme.SelectedValue.Length == 5) { // Extract the start and end time from the selected scheme int tempStartTime = Convert.ToInt32(scheme.SelectedValue.Substring(0,2)); int tempEndTime = Convert.ToInt32(scheme.SelectedValue.Substring(3,2)); // Find out which days to show/saves string tempMonday = "false"; string tempTuesday = "false"; string tempWednesday = "false"; string tempThursday = "false"; string tempFriday = "false"; string tempSaturday = "false"; string tempSunday = "false"; if (mondayCheckBox.Checked) tempMonday = "true"; if (tuesdayCheckBox.Checked) tempTuesday = "true"; if (wednesdayCheckBox.Checked) tempWednesday = "true"; if (thursdayCheckBox.Checked) tempThursday = "true"; if (fridayCheckBox.Checked) tempFriday = "true"; if (saturdayCheckBox.Checked) tempSaturday = "true"; if (sundayCheckBox.Checked) tempSunday = "true"; // Save the new settings webservice.UpdateSettings(tempStartTime, tempEndTime, tempMonday, tempTuesday, tempWednesday, tempThursday, tempFriday, tempSaturday, tempSunday, pType.SelectedValue); label.Text = GetString("SettingsUpdated"); } } catch { }
Jimmi added, "it's also worth noting the fact that the datatype to store the true/false values is nvarchar(5). What could possibly go wrong?"