some of my colleagues demand to avoid parameterless constructor and it's initialization completly. Because they tell me that a default initialization of a string property for example quickly hides the ability to find out the source of the error.
But a standard initialization of objects prevent the raise of a NullReferenceException in advance. And don't unit tests prevent those 'hard to find' errors?
So what is the best practice of doing this in C#?
What if i had a class with 10 Properties? Should the properties also be initialized via parameters of the constructor if i want to avoid the parameterless constructor? Isn't it to verbose?
For example i have this class, so people told me that i shouldn't do the default initialzation this way:
public class UserForCreationDto
{
public UserForCreationDto()
{
Username = "";
Email = "";
}
[Required]
[MaxLength(100)]
public string Username { get; set; }
[Required]
[MaxLength(100)]
public string Email { get; set; }
}