Is string.Length in C# (.NET) instant variable?

前端 未结 4 1114
陌清茗
陌清茗 2020-12-11 16:24

I\'m wondering if string.Length in C# is an instant variable. By instant variable I mean, when I create the string:

string A = \"\";

A = \"Som          


        
4条回答
  •  一个人的身影
    2020-12-11 17:05

    The length of the string is not computed, it is known at construction time. Since String is immutable, there will be no need for calculating it later.

    A .NET string is stored as a field containing the count of characters, and a corresponding series of unicode characters.

提交回复
热议问题