dimanche 13 mai 2012

Quick extension method to convert a yes/no value to a boolean

Once again, I'm not re-inventing the wheel,
Here are simple code, extension method in order to translate a yes/no (Y/N) value read somewhere to a boolean.



 public static class YesNoToBoolExtension
    {
        public static bool YesNotoBool(this string source)
        {
            return source.ToUpper() == "Y"||source.ToUpper()=="Yes";
        }

        public static bool YesNotoBool(this char source)
        {
            return char.ToUpper(source) == 'Y';
        }
    }

Good work ;-)

Aucun commentaire:

Publier un commentaire