M
M
Maxim Isaev2018-09-05 15:34:46
.NET
Maxim Isaev, 2018-09-05 15:34:46

Math.Abs ​​from string how does it work?

Good day to all! I came across this example

string str = "d4";
var res = Math.Abs(str[0]);
var res1 = Math.Abs(str[1]);

In this example, Math.Abs ​​takes the value "d" and matches it's encoding (which is 100), right?
Further, if str[1], the value changes to 55.
Can you explain why changing the values ​​in [] causes the results to change?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-09-05
@MaximIs

A string is an array of chars. Accordingly, [i] - will return the character of the string with the number i.

#
#, 2018-09-05
@mindtester

in this syntax, the string is iterated over as an array of characters, [] is interpreted as the index of such an array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question