+ 7

(Newbie question) if-else statement ignoring strings?

Now, I aknowledge this question may be a bit stupid but I couldn't find what was wrong with my code by myself so I thought I could ask for help on the forums. well, for context, I make simple codes in the code playground beetween courses to make sure that I can apply what I learned, but when I was testing if-else statements I was greeted with an error message that basically said that a string that I stored at the start of the code didn't exist. I attached my code with this post, so you can check it out to see what's wrong https://code.sololearn.com/clfkJiT8g5Lg/?ref=app

11th Jan 2019, 3:47 PM
Milanga
16 Answers
+ 11
To check for equality, use '==' instead of '='. And place string Manuel in double quotes like "Manuel".
11th Jan 2019, 4:04 PM
R_3-dr
R_3-dr - avatar
+ 9
To check for string equality use Equals methods: if(MyName.Equals("Manuel"))
11th Jan 2019, 4:18 PM
Ipang
+ 4
perfect!!
11th Jan 2019, 5:33 PM
Mohammad Elahi
Mohammad Elahi - avatar
+ 2
I think of ‘=‘ as ‘assign’ and == ( or === depending on language) as equals. This may help you too.
13th Jan 2019, 11:12 AM
Josephine
Josephine - avatar
+ 2
Guys. Of course my code works. BECAUSE IT'S FIXED. SOMEONE HELPED ME OUT.
20th Jan 2019, 9:20 PM
Milanga
+ 1
I wrote a commercial C sharp program in Visual Studios 10 that uses Forms for inputs. It is Tutorial for individuals studying Electronics! I have always loved science and engineering!
18th Jan 2019, 2:12 PM
Lloyd L Conley
Lloyd L Conley - avatar
+ 1
= is used for assigning a value to a varible. == is used in logic decisions comparing two varible to see if is true they are equal to each other.
25th Jan 2019, 10:08 AM
Lloyd L Conley
Lloyd L Conley - avatar
+ 1
What language are you programming?
30th Jan 2019, 2:25 PM
Lloyd L Conley
Lloyd L Conley - avatar
+ 1
This is code I corrected: String MyName = Console.ReadLine(); Notice I spelled string with a capital S
4th Mar 2019, 2:30 AM
Lloyd L Conley
Lloyd L Conley - avatar
0
And I do not get an error, everything works
13th Jan 2019, 6:26 PM
GrafGrihula
GrafGrihula - avatar
0
I found the bug! For C#, you don’t need the MyName.Equals(“text”). You just need an equality sign like MyName==“text here”. You do need to do that in Java, but not in C#! Here is a link to the fixed code. Link: https://code.sololearn.com/c48J0Tcmtk69/?ref=app
15th Jan 2019, 3:20 PM
Null.User
Null.User - avatar
0
I tested your code and did not have any errors! I used "Manuel" then "Sam" each time it branched to the correct output!
18th Jan 2019, 2:05 PM
Lloyd L Conley
Lloyd L Conley - avatar
0
Oh how can someone help you unless you send code with errors?
18th Jan 2019, 2:07 PM
Lloyd L Conley
Lloyd L Conley - avatar
0
Yes.
24th Jan 2019, 10:11 PM
Christopher Prater
Christopher Prater - avatar
0
its already fixed, no?
25th Jan 2019, 2:09 AM
ionizedbeam808
0
What if we wanna do greater or equal to?
3rd Mar 2019, 11:04 PM
SpacedOut
SpacedOut - avatar