I know that strings have variable length, therefore they need variable space in memory to be stored. When we define a string item in a struct
, the struct
's size would then be variable in length.
Older languages managed this by using fixed-length strings. However, there is no way to define fixed-length strings in C#, and C# manages normal strings in struct
s pretty good.
This becomes more weird when we define an array of such struct
s, or simply an array of strings. As result of any change (decrease/increase) in length of one string, all forward struct
s must be shifted.
How does C# handle variable-length strings in structs?