In terms of the size of an object, how do properties instead of Get / Set methods affect the size of an object if the properties set do not represent the state, but simply delegate its calls to getter and setter to another object?
For example, consider the following classes:
public class Person
{
Address _address = new Address();
public string AddressName
{
get{ return _address.Name; }
set { _address.Name = value; }
}
public string GetAddressName(){ return _address.Name; }
public void SetAddressName(string name){ _address.Name = name; }
}
public Address
{
public string Name { get; set; }
}
I assume that when a new Person is created, the CLR will consider the potential size of the AddressName property when determining how much memory will be allocated. However, if all I found is Get / Set AddressName methods, no extra memory will be allocated to serve the AddressName property. So, in order to save memory, it is better to use Get / Set methods in this case. However, this will not affect the Name property of the Address class, as the state is preserved. Is this assumption correct?