A string is an array of characters. Storing one in a struct does not store its character data inside the struct: the string is allocated on the heap, even if the struct itself is on the stack. Assigning a new value allocates another string; the old one remains until the garbage collector frees it. section 2.4.3
Listing 2.19 Struct with a string
public struct Enemy
{
public string Name;
public Vector2 Position;
public Vector2 Direction;
public float Velocity;
}The Enemy struct places a string field beside position, direction, and velocity data. section 2.4.3
Changing an enemy name
Assigning Enemy.Name = "Enemy Name" allocates string storage. Changing it to "New Name" allocates another string, while the previous one waits for garbage collection. Consider this allocation behavior when deciding whether a string belongs in performance-sensitive struct data. section 2.4.3



























