In your example you are not actually setting the property.
C# is smart enough to know that you are using an ICollection which can be publicly modified using Add, Remove, Clear, etc. What you are doing is the equivalent of this:
t.AddRange(new string[] { "hello", "goodbye" });
If you actually tried to do this it would not work:
var t = new Testing
{
ListOfStrings = new List<string>(),
};
EDIT:
Since you might be wondering how to expose a collection as readonly, you can do this by just exposing it as an IEnumerable:
public class Testing
{
private List<string> _listOfStrings;
public IEnumerable<string> MyStrings
{
get
{
foreach (var s in _myStrings)
yield return s;
}
}
public Testing()
{
_listOfStrings = new List<string>();
}
}
You could also create a readonly collection but I find that is more confusing. If you expose it as IEnumerable then consumers of the class can enumerate through the items with no ability to add or remove items.