Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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#.
Posted

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
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900