a problem in a simple code
ima tryna learn and got a idea of something but it doesnt seem to work does anyone know why?
29 Replies
figured it out the math needs to be a double
but what is this?
You forgot the parenthesis after
Console.ReadLine
What it's currently trying to do is convert the method itself to an integer, which it very obviously cannot do. You need to call the method, i.e. Console.ReadLine()
.
On a side-note, use int.Parse
instead of Convert.ToInt32
oh
thanks man
whats the difference?
int.Parse
is just kinda... better
For a variety of reasons: for one it doesn't allow you to try convert arbitrary objects to integers, and you happen to pass null
to it, it throws an exception instead of returning 0
.but for converting strings do i still use convert?
No, you use
TheTypeYouWantToConvertTo.Parse(yourString)
, eg. int.Parse(yourString)
, double.Parse(yourString)
, etc.it doesnt exist?
yea double and int work but string doesnt
If you want to convert something to a string then you just use
.ToString()
yourVariable.ToString()
i hate that bug
but why does it not say its a string?
So,
l.GetType
is a method. Methods are kinda weird, because you can both call them, but you can also pass them to other methods as values, just like numbers, string, etc. . When you pass a method as a value to another method, what you're actually passing is something called a Func
or an Action
, which you don't need to worry about what those actually are for now, but that's what's happening when you call Console.WriteLine(l.GetType)
- you're passing l.GetType
as a value to Console.WriteLine
.hm yea
And when
Console.WriteLine
tries to display a Func
or Action
, it prints out something like System.Func`1[System.Type]
So in general: if something is a method, you have to call it by putting ()
after it.oh
yea it shows as a sstring now
thank u
so basically anything that changes something or activate code
is called a function
and a function always have a () at the end of it
for it to be called?
Yep, although in C# a "function" is generally called a "method"
hm looks like i have to pass over my small knowledge of lua and python to c# xD
But yeah, functions/methods run other code.
ok
another question if i may
sure
do yk any good playlists for learning c#?
https://www.youtube.com/watch?v=wxznTygnRfQ&ab_channel=BroCode im watching bro code
Bro Code
YouTube
C# Full Course for free 🎮
C# tutorial beginners full course (C# for Unity)
#C# #tutorial #Unity
⭐️Time Stamps⭐️
#1 (00:00:00) C# tutorial for beginners
#2 (00:06:30) output 💬
#3 (00:10:48) variables ✖️
#4 (00:19:32) constants π
#5 (00:20:35) type casting 💱
#6 (00:27:49) user input ⌨️
#7 (00:31:24) arithmetic operators 🧮
#8 (00:35:54) Math class 📏
#9 (0...
after it i wanna learn more
Most people here will generally recommend $helloworld
after the course should i go watch helloworld?
sure
ok thanks man