473,473 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cannot implicitly convert type 'void' to 'string'

4 New Member
Expand|Select|Wrap|Line Numbers
  1. string codeentrd = Console.WriteLine("Enter the code for verification.", codeentrd );
  2.                 if (codeentrd.CompareTo("#2") == 0);
  3.                 {
  4.                     block = 2;
  5.                     continue;
  6.                 }
i don't understand why its an error please help
Dec 16 '12 #1
3 11383
PsychoCoder
465 Recognized Expert Moderator Contributor
Console.WriteLine does not return a value, so you're trying to convert a void (returns nothing) to a string which just isnt possible. Change that line to:

Expand|Select|Wrap|Line Numbers
  1. string codeentrd = Console.ReadLine("Enter the code for verification.");
  2.  
Dec 16 '12 #2
megamalo22
4 New Member
there is an error again 'No overload for method 'ReadLine' takes '1' arguments'
Dec 16 '12 #3
PsychoCoder
465 Recognized Expert Moderator Contributor
My bad, wasn't paying attention, use this:

Expand|Select|Wrap|Line Numbers
  1. Console.WriteLine("Enter the code for verification.");
  2. string codeentrd = Console.ReadLine();
  3.  
EDIT:

You'll want to check and make sure a value is provided before going any further to prevent your application from crashing. Something like this:

Expand|Select|Wrap|Line Numbers
  1. Console.WriteLine("Enter the code for verification.");
  2. string codeentrd = Console.ReadLine();
  3.  
  4. if(!string.IsNullOrEmpty(codeentrd)
  5. {
  6.       //do your work here
  7. }
  8. else
  9. {
  10.      //error message here
  11. }
  12.  
Dec 16 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Terminal882003 | last post by:
Hi, Here I have a question about MSCommLib. I need to dynamically add activeX controls that requires run-time license for MSCommLib. The following is the actual code: AxMSCommLib.AxMSComm...
22
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Jeff | last post by:
I get the following error: Cannot implicitly convert type 'Factory.Stack.pArrayStack' to 'Factory.Stack.StackDefs.ImStack' at compile time. I thought perhaps there was a mismatch between the...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
9
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
3
by: Patrick Olurotimi Ige | last post by:
compiling the code below i get the error:- Cannot implicitly convert type 'object'to 'System.Xml.XmlDocument' I'm getting the error on this line:- myXml.Document =...
1
by: alex21 | last post by:
Ok i am trying to use a Linq query to access a dictionary. public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();Using this Linq query: IEnumerable<Staff> loginquery...
2
by: ransaj | last post by:
objCompanyRequirement.Salary = Convert.ToInt32 (txtCRF_Salary.Text); cannot implicitly convert type 'int' to 'string' objCompanyRequirement.InterviewDate = ...
3
by: sappyjosh | last post by:
public void Update_Stock(Inseed Is) { if (con.State == ConnectionState.Open) { con.Close(); } try { ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.