c# - How to generically format a boolean to a Yes/No string? -
i display yes/no in different languages according boolean variable.
there generic way format according locale passed it?
if there isn't, standard way format boolean besides boolvar ? resources.yes : resources.no.
i'm guessing boolvar.tostring(iformatprovider) involved.
assumption correct?
the framework not provide (as far know). translating true/false yes/no not strike me more common other potential translations (such on/off, checked/unchecked, read-only/read-write or whatever).
i imagine easiest way encapsulate behavior make extension method wraps construct suggest in question:
public static class booleanextensions { public static string toyesnostring(this bool value) { return value ? resources.yes : resources.no; } } usage:
bool somevalue = getsomevalue(); console.writeline(somevalue.toyesnostring());
Comments
Post a Comment