53 Replies
This method returns a number
It doesn't convert in place
After all,
age
is a string
But I converted it
And it can only ever remain a string, it can only ever hold a string, it cannot, under any circumstance, hold an integer
Convert.ToInt32()
RETURNS a number
It doesn't change the variable you passedReturns to where?
Just... returns
To the left of it, let's say
Like any method that returns anything
But I want my string to be an int
age
was declared as a string, so it can only ever be a string
You need a new variable
An int
type variableThen whats convert even for?
For... converting a string into an int, in this case?
I mean, it does what you expect it to
You said it doesnt convert
Just returns
It converts the string into an integer and returns that integer
Yeah
As I said, C# is statically and strictly typed
But it doesnt work
A variable cannot change its type
It doesn't work because you're using it wrong
.
.
You're not using what the method returns
Simple as
You said 2 opposite things
I didn't?
The method doesn't change the type of any variable?
What method
Im just using main
Jesus
$helloworld
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
Nothing else
Start with the basics
I want my string to be converted to int
Angius#1586
REPL Result: Success
Console Output
Compile: 607.266ms | Execution: 34.749ms | React with ❌ to remove this embed.
And, really, go through the linked tutorials
You need to know the type system
You need to know what methods are
What type system
MODiX#0152
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
Quoted by
<@!85903769203642368> from #can't '-' int (click here)
React with ❌ to remove this embed.
That types in C# are strict and static and what it means, for example
I know what methods are
And Im using only main
I just want my string to be an int but it shows error
Why is this int number empty?
Why would it be?
It's not empty
![](https://utfs.io/f/a2a933d9-4ec0-48be-88d9-dddc38d76082-1nq2cb.png)
It's... not empty?
So you did convert that string after all
Yes?
But you said I can't
You can't convert IN PLACE
What place?
Wdym?
is NOT THE SAME as
you can't change the type of age
Variable
text
is STILL a string, and it STILL holds the value "420"
Variable number
is NEW and its type is int
The method converted the value and assigned it to a new variable
The old variable remains wholly and entirely unchanged"wholly and entirely unchanged"
very descriptive
They just said I cant
I have to make new variable
yes it's normal
Yes what?
age is define as a string you have to create a new variable to have an int
So I cant change its type like you said
you missed a t in
cant
![notlikethis](https://cdn.discordapp.com/emojis/504985305493798918.png)
Ok so variable is always same type and I have to make a new one with the same value for it to work
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.