将void转换为字符串问题 [英] Convert void to string problem

查看:100
本文介绍了将void转换为字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....我有一个问题..我有一个错误告诉我:无法将void类型隐式转换为字符串...我该如何解决?...如何将void转换为字符串? ...这在C#中.

hello everybody.... i have a problem .. i have an error telling me: Cannot implicity convert type void to string... how to i fix this?... how do i convert a void to string? ... this is in C#.

推荐答案

您无需将void转换为字符串;这个问题是不正确的.这是错误的解释编译器消息的方式:如果编译器告诉您不能执行A",则并不意味着您可以通过执行"A"来解决此问题.

您的错误消息应表示您正在尝试为字符串变量(类/结构字段/属性)分配函数返回的值;并且该函数的编译时返回类型与目标类型System.String不兼容.

这种情况的一种特殊情况是函数返回void.关键字"void"并不表示任何实型;它仅表示不返回任何内容的方法.这种方法因其副作用而被调用,根本无法出现在赋值操作中.

因此,您无需转换"任何内容-没有任何要转换的内容.您应该开始编写代码,以了解要写下的每个单词和分隔符的含义.

从一开始到最后阅读C#手册开始,然后进行简单的练习.现在,您需要非常缓慢地进行操作.

—SA
You never need to "convert" void to string; the question is incorrect. This is a wrong manner of interpretation of compiler messages: if compiler tells you "cannot do A", it does not mean you solve this by doing "A".

Your error message should mean that you''re trying to assign a string variable (class/structure field/property) a value returned by a function; and the compile-time return type of the function is not assignment-compatible with the target type, which is System.String.

A special case of this situation is the function returning void. The keyword "void" does not mean any real type; it simply means the method which returns nothing. Such method is called for its side effect and cannot appear in the assignment operation at all.

Therefore, you don''t need to "convert" anything — there is nothing to convert. You should start writing code understanding the meaning of every word and delimiter you''re writing down.

Start from reading C# manual from the very beginning to the very end doing simple exercises. Right now, you need to proceed really slowly.

—SA


您必须放置一些引发异常的代码,以获取有关问题的更多详细信息

通常,不需要将void转换为字符串
这就像您要让像"hello"这样的字符串转换成不可能的整数

谢谢
you have to put some code which is throwing exception for more detail about problem

Generally It is not required to convert void to string
This is something like you are asking string like "hello" to convert into integer which is not possible

Thanks


这篇关于将void转换为字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆