C
C#•12mo ago
LESZEK

help

why is doesn't work
No description
39 Replies
SinFluxx
SinFluxx•12mo ago
what is the type of name and what is the type of 5?
LESZEK
LESZEKOP•12mo ago
name its string 3 is int
SinFluxx
SinFluxx•12mo ago
right (I assume you mean 5 not 3) - so it can't compare them because they're different types
Thinker
Thinker•12mo ago
(btw you probably want to use == instead of is)
SinFluxx
SinFluxx•12mo ago
hint: hover your mouse where there are squiggly lines
LESZEK
LESZEKOP•12mo ago
and how to transform int to string
Thinker
Thinker•12mo ago
To be clear, you want to check whether name is the string 5?
LESZEK
LESZEKOP•12mo ago
no i want write cod, if I write 5 in cosole ,console write "siema" its dont work but] but i don write "
LESZEK
LESZEKOP•12mo ago
No description
LESZEK
LESZEKOP•12mo ago
now its working
SinFluxx
SinFluxx•12mo ago
It might look like it's working, but try entering something other than "Aleks"
LESZEK
LESZEKOP•12mo ago
its working
LESZEK
LESZEKOP•12mo ago
No description
SinFluxx
SinFluxx•12mo ago
no don't change your code, just enter something different in the console
LESZEK
LESZEKOP•12mo ago
but "23@#" its string oh ok
SinFluxx
SinFluxx•12mo ago
something that shouldn't make it write "siema"
LESZEK
LESZEKOP•12mo ago
No description
LESZEK
LESZEKOP•12mo ago
its dont working
SinFluxx
SinFluxx•12mo ago
right, see you've got part of your code underlined again
LESZEK
LESZEKOP•12mo ago
No description
SinFluxx
SinFluxx•12mo ago
No description
SinFluxx
SinFluxx•12mo ago
that's your ide trying to tell you something might not be right
LESZEK
LESZEKOP•12mo ago
''there was probably some empty punctuation by mistake''
SinFluxx
SinFluxx•12mo ago
yes, that semi colon shouldn't be there, because it being there meant that Console.WriteLine("siema"); wasn't part of your if statement any more
LESZEK
LESZEKOP•12mo ago
oh i se its dont works but its not the same grooup how to write if I write in console no word aleks its console write "its dont this word " i mean
SinFluxx
SinFluxx•12mo ago
you can use an else statement to go with your if
LESZEK
LESZEKOP•12mo ago
No description
LESZEK
LESZEKOP•12mo ago
like this ok
SinFluxx
SinFluxx•12mo ago
And like Thinker said earlier, if you're comparing values then it should be ==, i.e. if(name == "Aleks"), not =
LESZEK
LESZEKOP•12mo ago
No description
SinFluxx
SinFluxx•12mo ago
See my last message Also the else doesn't need any condition with it
if (name == "Aleks")
...
else
...
if (name == "Aleks")
...
else
...
Also it will help to read it if you format your code right 🙂 so instead of:
if (name == "Aleks")
Console.WriteLine("siema");
if (name == "Aleks")
Console.WriteLine("siema");
do:
if (name == "Aleks")
Console.WriteLine("siema");
if (name == "Aleks")
Console.WriteLine("siema");
or
if (name == "Aleks")
{
Console.WriteLine("siema");
}
if (name == "Aleks")
{
Console.WriteLine("siema");
}
LESZEK
LESZEKOP•12mo ago
thx now its working
LESZEK
LESZEKOP•12mo ago
No description
SinFluxx
SinFluxx•12mo ago
And again like Thinker said earlier, in this instance you probably want == instead of is
LESZEK
LESZEKOP•12mo ago
because i thinks else end if muss be in the same groyp what is the difference between "is" and ==
SinFluxx
SinFluxx•12mo ago
"is" is usually used for checking the type of something
ZacharyPatten
ZacharyPatten•12mo ago
nowadays you can use is to perform an equality check against constant values. it isn't just used for type checking the main difference between == and is is that == is overloadable, meaning that in order to know what == will do you have to actually go to the operator overload and check. is only works with constant values (and therefore a set number of types) and cannot be overloaded. So, if you are dealing with primitive types it is generally a better idea to use is over == in my opinion in other words... you always know what is will do when you see it in code but you don't always know what == will do
SinFluxx
SinFluxx•12mo ago
ah fair enough 🙂
Thinker
Thinker•12mo ago
tl;dr, is only lets you check for constant values like "Aleks" and 5, not for other variables, for instance if you have a string variable called friendName you wouldn't be able to do name is friendName, but you could do name == friendName.
Want results from more Discord servers?
Add your server