Converting C# to Pascal i stumble upon this line:

if (bb[1] == '1'-'0')

What does it mean? If second byte is equal to string '1' minus string '0'?

有帮助吗?

解决方案

'1'-'0' this would give you the 1 as integer value. It is like converting character to respective integer number.

It is same as:

int value = (int)Char.GetNumericValue('1');

where value will hold 1

so your check is:

if(bb[1] == 1)

其他提示

C# doesn't have single-quoted strings, so those are both characters (type char).

Values of type char are represented in memory as the integer value of their ASCII code, so some limited math operations work on them (like subtraction in your example).

'1' - '0' is the same as (int)'1' - (int)'0' which is 49 - 48.

watch window in visual studio

'1' is converted to decimal which corresponds to 49, '0' as decimal gives 48. 49 - 48 = 1. So '1' - '0' is 1 as shown in the watch window. Here's ASCII character set if you have other similar comparisons.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top