Why does a struct automatically generate a public parameter-less constructor if a parameterized one is defined

Viewed 114
struct str {
    public str(int n) { }
}
   
    
class tes {
    public tes(int h) { }
}
    

//main method
tes uhi = new();  //error no such constructor
str uhi1 = new();

I can see that for a class, if I define a parameterized constructor that the default one is no longer available but in case of structs, the compiler automatically generates a public parameter-less constructor even if I define a parameterized one.

Can you please tell me why is that so?

0 Answers
Related