C
C#•2y ago
LESZEK

help

why is doesn't work
No description
39 Replies
SinFluxx
SinFluxx•2y ago
what is the type of name and what is the type of 5?
LESZEK
LESZEKOP•2y ago
name its string 3 is int
SinFluxx
SinFluxx•2y ago
right (I assume you mean 5 not 3) - so it can't compare them because they're different types
Thinker
Thinker•2y ago
(btw you probably want to use == instead of is)
SinFluxx
SinFluxx•2y ago
hint: hover your mouse where there are squiggly lines
LESZEK
LESZEKOP•2y ago
and how to transform int to string
Thinker
Thinker•2y ago
To be clear, you want to check whether name is the string 5?
LESZEK
LESZEKOP•2y 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•2y ago
No description
LESZEK
LESZEKOP•2y ago
now its working
SinFluxx
SinFluxx•2y ago
It might look like it's working, but try entering something other than "Aleks"
LESZEK
LESZEKOP•2y ago
its working
LESZEK
LESZEKOP•2y ago
No description
SinFluxx
SinFluxx•2y ago
no don't change your code, just enter something different in the console
LESZEK
LESZEKOP•2y ago
but "23@#" its string oh ok
SinFluxx
SinFluxx•2y ago
something that shouldn't make it write "siema"
LESZEK
LESZEKOP•2y ago
No description
LESZEK
LESZEKOP•2y ago
its dont working
SinFluxx
SinFluxx•2y ago
right, see you've got part of your code underlined again
LESZEK
LESZEKOP•2y ago
No description
SinFluxx
SinFluxx•2y ago
No description
SinFluxx
SinFluxx•2y ago
that's your ide trying to tell you something might not be right
LESZEK
LESZEKOP•2y ago
''there was probably some empty punctuation by mistake''
SinFluxx
SinFluxx•2y 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•2y 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•2y ago
you can use an else statement to go with your if
LESZEK
LESZEKOP•2y ago
No description
LESZEK
LESZEKOP•2y ago
like this ok
SinFluxx
SinFluxx•2y ago
And like Thinker said earlier, if you're comparing values then it should be ==, i.e. if(name == "Aleks"), not =
LESZEK
LESZEKOP•2y ago
No description
SinFluxx
SinFluxx•2y 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•2y ago
thx now its working
LESZEK
LESZEKOP•2y ago
No description
SinFluxx
SinFluxx•2y ago
And again like Thinker said earlier, in this instance you probably want == instead of is
LESZEK
LESZEKOP•2y ago
because i thinks else end if muss be in the same groyp what is the difference between "is" and ==
SinFluxx
SinFluxx•2y ago
"is" is usually used for checking the type of something
ZacharyPatten
ZacharyPatten•2y 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•2y ago
ah fair enough 🙂
Thinker
Thinker•2y 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.

Did you find this page helpful?