Why dont Work?

Gabry_v

Member
Joined
Oct 2, 2019
Messages
8
Programming Experience
Beginner
string ris;
Console.WriteLine ("do you want to read?'");
ris = (Console.ReadLine ());
if (ris = 's')
Console.WriteLine ( " blablabla");
else
Console.WriteLine ("press any key to continue..");
Console.ReadKey ();
 
What errors are you getting? Have you tried fixing things based on the error messages?
 
Visual Express or Visual Studio?

Any which way, you should be getting compilation errors and warnings. What are those? What have you done to try to understand the error messages and try to resolve them?
 
Visual Studio 2019
 

Attachments

  • Cattura.PNG
    Cattura.PNG
    16.3 KB · Views: 37
Last edited by a moderator:
As mentioned in your closed thread, this is an English language forum, please use English.

If you press F5 to compile and run your program, errors will reported because your program will fail to compile. View the "Errors and Warnings" pane in Visual Studio to see the errors and warnings. Fix those.

In the future, please post your actual code and errors, not screenshots.

Anyway, you are facing several issues. The first of which is that you are trying to assign a character to a string. That doesn't work in C# because C# is strongly typed.

The next issue you are facing is that you are doing an assignment when you should really be doing a comparison.

Out of curiosity, what book or tutorial are you using to learn C#? A lot of these issues could have been avoided if you were learning C# in a structured manner.
 
currently attending high school, the professor has begun to explain us c # for about two weeks, he explained to us the integers: int and long, the real ones: float and double bool, string and char. as a textbook we use "E PROGRAMM", an Italian book, I don't know if there is an English variant. we also did the if and do while loops, unfortunately the professor didn't focus so much on the ways to insert with string, int etc. .. and I didn't understand them much, on the contrary I understood the do do and if loops.
 
Well, it's time to review your class notes on string vs char. Also take time to talk to your classmate to see what they learned/understood.
 
Hi Gabry_v, I advise you spend some time on MSDN, and study the material from there. Most schools who try teaching coding now a days use outdated and often old books not worthy of wiping your ass with. Not criticising "E PROGRAMM", I've just never heard of it, nor has Google. As a hypothesis, its really an assumption on my part given how many times I've corrected school book material on forums over the years. However, one of the most practical ways to learn; is to read and study the content provided by Microsoft themselves. As you are guaranteed, almost all of their pages are kept updated.

In regards your issue, there is an if else link for conditional logic in my signature. I suggest reading that so you can see why your if statement is not formatted correctly. Strings are also enclosed in double quotation marks " ", and not single quotes ' '. I think its safe to assume you were trying to determine if you received the typed character which was in fact the letter "s"? Breezing over Strings - C# Programming Guide will help you here too. If you get stuck, use the search bar on MSDN to look up whatever you're struggling to understand, ie char etc. Of course, if you need further clarity, or have any questions. You can always come back and ask on these forums.
 
Hi Gabry_v, I advise you spend some time on MSDN, and study the material from there. Most schools who try teaching coding now a days use outdated and often old books not worthy of wiping your ass with. Not criticising "E PROGRAMM", I've just never heard of it, nor has Google. As a hypothesis, its really an assumption on my part given how many times I've corrected school book material on forums over the years. However, one of the most practical ways to learn; is to read and study the content provided by Microsoft themselves. As you are guaranteed, almost all of their pages are kept updated.

In regards your issue, there is an if else link for conditional logic in my signature. I suggest reading that so you can see why your if statement is not formatted correctly. Strings are also enclosed in double quotation marks " ", and not single quotes ' '. I think its safe to assume you were trying to determine if you received the typed character which was in fact the letter "s"? Breezing over Strings - C# Programming Guide will help you here too. If you get stuck, use the search bar on MSDN to look up whatever you're struggling to understand, ie char etc. Of course, if you need further clarity, or have any questions. You can always come back and ask on these forums.
I will, thank u very much for your help
 
Back
Top Bottom