I have a property like this:
public Tuple<String, String>[] Breadcrumbs { get; set; }
and I have a test in one of my methods like this:
if (Breadcrumbs != null && Breadcrumbs.Length > 0) { }
Depending on when this method is called, Breadcrumbs may not have been set. In one test, Breadcrumbs == null evaulates to true.
Will unset properties always have a value? (Will it always be null?)
An automatically-implemented property which hasn’t been explicitly set by any code will always have the default value for the property type – which is null for reference types. (For
intit would be 0, forcharit would be ‘\0’ etc).An automatically implemented property like this is just equivalent to:
… except that the backing variable has an unspeakable name (you can’t refer to it in code) so it will always start off with the default value for the type.