105 Replies
changed it slightly
How do you set the value of a variable?
and how do you check if a value is equals to another value?
you just.. use =?
==..?
im trying to get it to return false if the email doesnt have a @ and a .
Correct
and check your code
ok
Read it out for yourself
also I suggest you check Microsoft documentation https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/selection-statements#the-if-statement
if and switch statements - select a code path to execute - C# refer...
The
if
and switch
statements provide branching logic in C#. You use if,
else and
switch` to choose the path your program follows.but apparently..
compare your if statement to what you wrote earlier
Setting the value versus comparing a value
all i did was add a space to else if and change the = to ==
And one more thing. Compare the example given in the microsoft documentation
Last thing
You have a character in your code that does not exist in the example
im ngl
i dont understand the documentation at all
i leant c# in 3 hours
for school
the basic basics ofc
Do you see any semicolons in the if-statement?
nope
huh
Now, do you see any in yours?
well yeah but if i get rid of it
it tells me to add it back
Please show the code
variables cannot have a space in them
oh oops
yeah.. idk if i can cope with this
What exactly do you want to make?
i want to input text and check to see if it has at least 1 @ and 1 .
if it doesnt have both then it tells you your email is invalid
Name your class
Program
change main
to Main
with a capital M, and remove all the parameters and put string[] args
instead.
Unless you have the ability to use top-level statements that's what you have to do.mkay
But I have no idea what the site requires.
idk either i just cant use vscode so im stuck with this random compiler
since vscode refuses to run
Did you follow this $vscode ?
Follow the instructions here on getting started with DevKit for C# in VSCode: https://code.visualstudio.com/docs/csharp/get-started
Get started with C# and .NET in Visual Studio Code
Getting Started with C# and .NET Development in Visual Studio Code
yup
doesnt work
It might be easier to use Visual Studio Community 2022
VSCode is not for beginners
And is not the same program as Visual Studio Community
VS is an IDE whereas VSCode is not.
meaning VS will install everything you need.
i tried using vs 2022
also didnt work
i can retry though
define didn't work
like
i tried running some program
and it gave me errors not related to the program at all
that i didnt understand
i asked for help
any examples?
one second
just didnt wanna work in vs 2022
but it worked on this random compiler
ill reinstall vs 2022 but idk if i can get it to work
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
Make sure you use .NET (and not .NET Framework)
Not that it has anything to do with the error.
and worst case scenario you might just need to reinstall .NET
ive installed it 3 times
literally
64 bit and 82(or 84 idk) bit
I can't see any errors with that code. Did you copy paste it?
yeah
copy pasted 1 to 1
Then that might be it
You could've accidentally pasted an invisible character
And site maybe filters those out.
ok im signing into vs2022
i assume its this
Make sure you do not open a folder as C# is project based and not file based
oh
so please go through the project wizard
by pressing new project
?
You must install the
.net desktop development
workload
you can find it by running Visual Studio Installer and pressing modify
There should be an app installed when you install Visual Studio, so you can just search for itThis should be checked
alright
for you it's called
.NET desktop development
I don't have visual studio installed so it's called so for me because I only have the build tools (without the IDE).im downloading it at
m
Sweet!
After it's installed you should see a bunch of templates to your right.
Here:
Then you create a
Console Application
project
and you'll have a template ready to gothis framework?
That runtime, correct.
Remember what I said before about top-level statements?
yeah
using string [] args
This time you don't have to do so.
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0ATEBqAPgAQCYBGAWACh9iBOACgCIAJGAGxYgAIB1aFjAQnoBKANxA=
SharpLab
C#/VB/F# compiler playground.
Left side is your code; right side is what the compiler spits out (meaning not something you have to write).
So you can forget about the entry-point
oooh
That's what top-level statements does.
Note that it is only for one file (the entry-point)
ok i wanna ask something though
see how i kinda need to check
if @ is entered right
is IndexOf the right way to do that?
cause these r the errors im getting
It's definitely a fast way of doing so, yes.
You can however optimize it by instead declaring
@
as a char
meaning a single character
you can do so like this
those single quotations means a characterah
mk
ok so
if i make Isearch a bool
itll return false if @ isnt entered
right?
here
Oh, yeah. IndexOf returns the index of where the character was found
I suggest reading the documentation of IndexOf
https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-8.0
Specifically this
Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.The latter part
so itll return -1 if its not found
alright
Correct
ill just check to see if -1 is returned then
Correct
i can do that by.... doing if Isearch == -1
right?
First you must change your ISearch's to an integer
but yes, and that means it has not been found in the text
done
getting a lot of red lines
thats perfectly fine thats what I want
You cannot declare variables multiple times
check your code again
oops
i thought you could
ok
apparently i cant use or
thats different from
python
so
&&
is or
thats what im getting
Read again
or is it ||??
Yes,
||
is ORoh
ok thats kinda cryptic
Remember what I mentioned earlier, the semicolon
...
OH
right
now..
if you want to combine them, it must be in a single
if (foo == true || bar == false) { .. }
and that means IF foo is true OR bar is false THEN
(pseudocode)ah i see
IT WORKS
OH MY DAYS
IT WORKS
YOURE A GODSEND
Amazing!
That's all I can help you for today.
Good luck on your journey!
š
THANK YOU š
Anytime. :catpog:
$close
If you have no further questions, please use /close to mark the forum thread as answered