<tfoot id='WXv0I'></tfoot>

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

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

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

      <legend id='WXv0I'><style id='WXv0I'><dir id='WXv0I'><q id='WXv0I'></q></dir></style></legend>

      无法将类型“X"隐式转换为“字符串"——它何时以及如何确定它“不能"?

      Cannot implicitly convert type #39;X#39; to #39;string#39; - when and how it decides that it quot;cannotquot;?(无法将类型“X隐式转换为“字符串——它何时以及如何确定它“不能?)

    1. <small id='ogvGW'></small><noframes id='ogvGW'>

        <bdo id='ogvGW'></bdo><ul id='ogvGW'></ul>

            <legend id='ogvGW'><style id='ogvGW'><dir id='ogvGW'><q id='ogvGW'></q></dir></style></legend>
                <tbody id='ogvGW'></tbody>

              <i id='ogvGW'><tr id='ogvGW'><dt id='ogvGW'><q id='ogvGW'><span id='ogvGW'><b id='ogvGW'><form id='ogvGW'><ins id='ogvGW'></ins><ul id='ogvGW'></ul><sub id='ogvGW'></sub></form><legend id='ogvGW'></legend><bdo id='ogvGW'><pre id='ogvGW'><center id='ogvGW'></center></pre></bdo></b><th id='ogvGW'></th></span></q></dt></tr></i><div id='ogvGW'><tfoot id='ogvGW'></tfoot><dl id='ogvGW'><fieldset id='ogvGW'></fieldset></dl></div>
                <tfoot id='ogvGW'></tfoot>
                本文介绍了无法将类型“X"隐式转换为“字符串"——它何时以及如何确定它“不能"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                现在我正在使用 Guids.

                我当然记得,在整个代码中,这种隐式转换在某些地方有效,而在其他地方则无效.直到现在我都看不到这种模式.

                I certainly remember that throughout the code in some places this implicit conversion works, in others it does not. Until now I fail to see the pattern.

                编译器如何决定什么时候不能?我的意思是,类型方法 Guid.ToString() 是存在的,不是在需要这种转换时调用吗?

                How the compiler decides when it cannot? I mean, the type method Guid.ToString() is present, isn't it called whenever this transformation is needed?

                谁能告诉我这种转换是在什么情况下自动完成的,我什么时候必须显式调用 myInstance.ToString()?

                Can someone please tell me under what circumstances this transformation is done automatically and when I have to call myInstance.ToString() explicitly?

                推荐答案

                简而言之,当定义了隐式或显式转换运算符时:

                In short, when there is an implicit or explicit conversion operator defined:

                class WithImplicit {
                    public static implicit operator string(WithImplicit x) {
                        return x.ToString();}
                }
                class WithExplicit {
                    public static explicit operator string(WithExplicit x) {
                        return x.ToString(); }
                }
                class WithNone { }
                
                class Program {
                    static void Main() {
                        var imp = new WithImplicit();
                        var exp = new WithExplicit();
                        var none = new WithNone();
                        string s1 = imp;
                        string s2 = (string)exp;
                        string s3 = none.ToString();
                    } 
                }
                

                这篇关于无法将类型“X"隐式转换为“字符串"——它何时以及如何确定它“不能"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                Multi-color TextBox C#(多色文本框 C#)
                How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                C# Numeric Only TextBox Control(C# 纯数字文本框控件)

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

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

                        <tbody id='zhrWj'></tbody>
                      <legend id='zhrWj'><style id='zhrWj'><dir id='zhrWj'><q id='zhrWj'></q></dir></style></legend>
                      <tfoot id='zhrWj'></tfoot>
                        • <bdo id='zhrWj'></bdo><ul id='zhrWj'></ul>