系统类型;(System.Type; implicit cast to string)

编程入门 行业动态 更新时间:2024-10-20 03:20:40
系统类型;(System.Type; implicit cast to string)

在查看代码定义窗口下的System.Type类时,我似乎无法理解如何将此类的实例隐式转换为字符串。 例如,在以下代码中:

int foo = 0; Console.WriteLine("Hi! I'm a type of type {0}", foo.GetType());

如何将GetType()产生的System.Type隐式转换为字符串?

While looking at the System.Type class under the Code Definition Window, I cannot seem to understand how an instance of this class is implicitly cast to string. For example, on the following code:

int foo = 0; Console.WriteLine("Hi! I'm a type of type {0}", foo.GetType());

How was the System.Type resulting from GetType() implicitly cast to string?

最满意答案

它不是隐式地转换为字符串。 它被转换为Object (使用标准的隐式引用转换),并且String.Format正确地格式化它 - 在这种情况下通过调用ToString 。

不是在编译时完成的。 您显示的代码调用Console.WriteLine(string, object)重载。

It's not being implicitly cast to string. It's being converted to Object (with the standard implicit reference conversion), and String.Format is formatting it appropriately - by calling ToString in this case.

This is not being done at compile-time. The code you've shown calls the Console.WriteLine(string, object) overload.

更多推荐

本文发布于:2023-07-04 17:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   系统   System   Type   cast

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!