As John already mentioned, ConfigurationSettings.AppSettings
is a NameValueCollection
which returns it's items as Strings.
Personally, I hate to see this kind of code... people attaching a ToString() call to just about every property, regardless of whether it returns a string in the first place. Unfortunately, I get to see it all too often. My guess is that it makes people feel comforted... somehow, as if they're following recommended guidelines for writing beautiful code. :P
What they don't seem to realize is that calling ToString()
on a Null object will throw an exception. For instance, in your example, if the "Foo" key did not exist in the AppSettings section of Configuration, a NullReferenceException
would be thrown by the code.