How to know the size of the string in bytes?

后端 未结 3 1502
梦毁少年i
梦毁少年i 2020-11-27 14:50

I\'m wondering if I can know how long in bytes for a string in C#, anyone know?

3条回答
  •  被撕碎了的回忆
    2020-11-27 15:15

    From MSDN:

    A String object is a sequential collection of System.Char objects that represent a string.

    So you can use this:

    var howManyBytes = yourString.Length * sizeof(Char);
    

提交回复
热议问题