Write a C# Sharp program to swap two numbers.Test Data:Input the First Number : 5Input the Second
the above is the question
44 Replies
this my answer and its not working
This doesn't compile because you're assigning a string to an int.
console.ReadLine()
returns a string. Either you'd have to make NUM1, NUM2 and temp a string, or you'd have to parse the strings.
$parseuse
$tryparse
$tryparse
When you don't know if a string is actually a number when handling user input, use
int.TryParse
(or variants, e.g. double.TryParse
)
TryParse
returns a bool
, where true
indicates successful parsing.
Remarks:
- Avoid int.Parse
if you do not know if the value parsed is definitely a number.
- Avoid Convert.ToInt32
entirely, this is an older method and Parse
should be preferred where you know the string can be parsed.
Read more herei did parse
Not in the code you pasted above.
that wont compile,
int.parse
isnt int.Parse
most programming languages are case sensitivedamn
/tmp/VvCT1xFkqp.cs(23,49): error CS1002: ; expected
/tmp/VvCT1xFkqp.cs(23,49): error CS1513: } expected
like am using an online compliler
cuz vs code not running any code
runs just fine, https://dotnetfiddle.net/uqAXGX
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
well guys do have any suggestions for execercises based learning for c#
$helloworld
https://learn.microsoft.com/en-us/dotnet/csharp/
all these are good resources
There is a course platform called Dometrain that currently has their "Intro to C#" course free for the rest of march, so that might be worth checking out if you like video content
Thx a lot btw it better if i grinded mainstream C# before unity version?
Unity... where do I even begin...
So, unity uses C#, but a slightly lower "language version" than "normal modern .NET"
thats not really the problem
Bro i be lackin monobehavior
the problem is that unity just does everything differently. It has a different standard library. It compiles to C++ :d
So what is "best practice" in normal C# is terrible in Unity, and vice-versa.
so what do i do
idk where to start
Do you care about learning "normal C#"?
and like if i have to code for unity i have to make the whole game
or is your only goal of learning this to make a game in Unity?
yes
If Unity is your end-goal, learn unity
maybe learn the absolute basics of C# first, like classes, methods etc
but dont go deep
ok w3schools?
up to where?
just be aware! if you do this, you will NOT actually know modern .net development
You will not know "normal C#". Thats fine, just keep that in mind
so you say if i take the hard path
No its two different paths.
One isnt harder than the other
they just diverge a lot
its the same language, but learning the language itself isnt the problem
choice's i cant come back to change
Unlearning what you already know is hard tbh
its doable, but its hard
old habits die hard etc
i wanna be a full fledged C# 3d dev on unity
then thats what you should do
unity in a nutshell is just that i have to learn every game dev skill just for programming
https://learn.microsoft.com/en-us/collections/yz26f8y64n7k07?WT.mc_id=dotnet-35129-website
Go here. Do all the "learning path" modules imho
ok
then go learn unity from people who know unity
Also, at that point, $unity is where you go for help
not here
This is a discord for "normal" C# development, not unity
am already joined there
we have #game-dev where some people who know unity hang around, but they are the experts on unity
thank you for you wisdom
i think the best way to learn is to join a dev team of begginers
and do each part
¯\_(ツ)_/¯
the best way to learn would be to have at least one experienced person to learn from