C# String.Length from Microsoft Documentation

前端 未结 2 1880
情歌与酒
情歌与酒 2021-01-28 22:20

Microsoft documentation states that this code will return 7 characters

The Length property returns the number of Char objects in this instance, not

2条回答
  •  死守一世寂寞
    2021-01-28 23:02

    You would have to prevent the interpretation of the literal by the compiler. This can be done with the @ prefix, like this:

    var characters = @"abc\u0000def";
    

    The Length property of this string will then return 12, but there will no longer be an actual unicode character in the string.

提交回复
热议问题