<i id='V6FwE'><tr id='V6FwE'><dt id='V6FwE'><q id='V6FwE'><span id='V6FwE'><b id='V6FwE'><form id='V6FwE'><ins id='V6FwE'></ins><ul id='V6FwE'></ul><sub id='V6FwE'></sub></form><legend id='V6FwE'></legend><bdo id='V6FwE'><pre id='V6FwE'><center id='V6FwE'></center></pre></bdo></b><th id='V6FwE'></th></span></q></dt></tr></i><div id='V6FwE'><tfoot id='V6FwE'></tfoot><dl id='V6FwE'><fieldset id='V6FwE'></fieldset></dl></div>

      <small id='V6FwE'></small><noframes id='V6FwE'>

      • <bdo id='V6FwE'></bdo><ul id='V6FwE'></ul>

    1. <legend id='V6FwE'><style id='V6FwE'><dir id='V6FwE'><q id='V6FwE'></q></dir></style></legend>
    2. <tfoot id='V6FwE'></tfoot>

      如何将布尔值一般格式化为是/否字符串?

      How to generically format a boolean to a Yes/No string?(如何将布尔值一般格式化为是/否字符串?)

        1. <tfoot id='9ior0'></tfoot><legend id='9ior0'><style id='9ior0'><dir id='9ior0'><q id='9ior0'></q></dir></style></legend>
            <bdo id='9ior0'></bdo><ul id='9ior0'></ul>

            <i id='9ior0'><tr id='9ior0'><dt id='9ior0'><q id='9ior0'><span id='9ior0'><b id='9ior0'><form id='9ior0'><ins id='9ior0'></ins><ul id='9ior0'></ul><sub id='9ior0'></sub></form><legend id='9ior0'></legend><bdo id='9ior0'><pre id='9ior0'><center id='9ior0'></center></pre></bdo></b><th id='9ior0'></th></span></q></dt></tr></i><div id='9ior0'><tfoot id='9ior0'></tfoot><dl id='9ior0'><fieldset id='9ior0'></fieldset></dl></div>

                  <tbody id='9ior0'></tbody>

                <small id='9ior0'></small><noframes id='9ior0'>

              • 本文介绍了如何将布尔值一般格式化为是/否字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我想根据一些布尔变量以不同的语言显示是/否.
                是否有根据传递给它的语言环境对其进行格式化的通用方法?
                如果没有,除了 boolVar 之外,格式化布尔值的标准方法是什么?Resources.Yes : Resources.No.
                我猜这涉及到 boolVar.ToString(IFormatProvider).
                我的假设正确吗?

                I would like to display Yes/No in different languages according to some boolean variable.
                Is there a generic way to format it according to the locale passed to it?
                If there isn't, what is the standard way to format a boolean besides boolVar ? Resources.Yes : Resources.No.
                I'm guessing that boolVar.ToString(IFormatProvider) is involved.
                Is my assumption correct?

                推荐答案

                框架本身并没有为你提供这个(据我所知).将 true/false 翻译成 yes/no 并没有让我觉得比其他潜在翻译更常见(例如 on/off已选中/未选中只读/读写或其他).

                The framework itself does not provide this for you (as far as I know). Translating true/false into yes/no does not strike me as more common than other potential translations (such as on/off, checked/unchecked, read-only/read-write or whatever).

                我认为封装行为的最简单方法是创建一个扩展方法,该方法包含您在问题中建议自己的构造:

                I imagine that the easiest way to encapsulate the behavior is to make an extension method that wraps the construct that you suggest yourself in your question:

                public static class BooleanExtensions
                {
                    public static string ToYesNoString(this bool value)
                    {
                        return value ? Resources.Yes : Resources.No;
                    }
                }
                

                用法:

                bool someValue = GetSomeValue();
                Console.WriteLine(someValue.ToYesNoString());
                

                这篇关于如何将布尔值一般格式化为是/否字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)
                  <tfoot id='lSFKT'></tfoot>

                  <small id='lSFKT'></small><noframes id='lSFKT'>

                      • <bdo id='lSFKT'></bdo><ul id='lSFKT'></ul>
                          <i id='lSFKT'><tr id='lSFKT'><dt id='lSFKT'><q id='lSFKT'><span id='lSFKT'><b id='lSFKT'><form id='lSFKT'><ins id='lSFKT'></ins><ul id='lSFKT'></ul><sub id='lSFKT'></sub></form><legend id='lSFKT'></legend><bdo id='lSFKT'><pre id='lSFKT'><center id='lSFKT'></center></pre></bdo></b><th id='lSFKT'></th></span></q></dt></tr></i><div id='lSFKT'><tfoot id='lSFKT'></tfoot><dl id='lSFKT'><fieldset id='lSFKT'></fieldset></dl></div>
                          <legend id='lSFKT'><style id='lSFKT'><dir id='lSFKT'><q id='lSFKT'></q></dir></style></legend>
                            <tbody id='lSFKT'></tbody>