Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding 48 to string number

Tags:

c#

I have a string in C# like this:

string only_number;

I assigned it a value = 40

When I check only_number[0], I get 52
When I check only_number[1], I get 48

why it is adding 48 to a character at current position? Please suggest

like image 350
DotnetSparrow Avatar asked May 17 '26 07:05

DotnetSparrow


1 Answers

String is basically char[]. So what you are seeing is ASCII value of char 4 and 0.

Proof: Diff between 4 and 0 = Diff between 52 and 48.

Since it is a string so you didn't assigned it 40. Instead you assigned it "40".

like image 153
Nikhil Agrawal Avatar answered May 19 '26 21:05

Nikhil Agrawal