Parameterless constructors in structs for C# 6

后端 未结 2 1158
孤街浪徒
孤街浪徒 2020-12-10 01:02

My understanding is that Parameterless constructors in structs are now allowed.

But the following gives me a compile error in VS 2015 Community

publi         


        
2条回答
  •  Happy的楠姐
    2020-12-10 01:29

    I'm not sure why, however, this is allowed:

    public struct Person 
    { 
        public string Name { get; } 
        public int Age { get; } 
        public Person(string name = null, int age = 0) { Name = name; Age = age; } 
    }
    

    Does that solve your problem?

提交回复
热议问题