Encoding used in cast from char to byte

前端 未结 3 542
死守一世寂寞
死守一世寂寞 2020-12-18 01:37

Take a look at the following C# code (function extracted from the BuildProtectedURLWithValidity function in http://wmsauth.org/examples):

byte[]         


        
3条回答
  •  抹茶落季
    2020-12-18 02:19

    Casting between byte and char is like using the ISO-8859-1 encoding (= the first 256 characters of Unicode), except it silently loses information when encoding characters beyond U+00FF.

    And besides, is the char actually bigger than a byte (I'm guessing 2 bytes) and will actually omit the first byte?

    Yes. A C# char = UTF-16 code unit = 2 bytes.

提交回复
热议问题