This question is simply to satisfy my interest. Reading Choosing Between Classes and Structures the page says "It has an instance size smaller than 16 bytes.".
Given this simple immutable struct
.
public struct Coordinate
{
private readonly double _latitude;
private readonly double _longitude;
public Coordinate(double latitude, double longitude)
{
_latitude = latitude;
_longitude = longitude;
}
public double Latitude
{
get { return _latitude; }
}
public double Longitude
{
get { return _longitude; }
}
}
Do properties also count towards the 16 byte limit? Or do only fields count?
If the latter wouldn't using a struct
fail the guidelines provided by Microsoft since a double is 8 bytes? Two doubles would be 16 bytes which is exactly 16 bytes and not less.