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