Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When I try to type all this out for a struct/structure without the bits in bold, I am getting squiggly error lines. Why is it that when I add the :this() to the code, the squiggly lines disappear? This error doesn't appear for classes but they will for structs.

 struct Line
    {
        private Point point1 { get; set; }
        private Point point2 { get; set; }

        readonly double Length;
        readonly double Slope;

        public Line(Point p1, Point p2):this()
        {
            point1 = p1;
            point2 = p2;
        }
}
Posted
Updated 15-Oct-12 12:54pm
v5
Comments
n.podbielski 15-Oct-12 19:18pm    
"I am getting squiggly error lines."

Thats funny way of saying about Intellisense errors notifications.
FourCrate 15-Oct-12 19:23pm    
haha I'm strange...

1 solution

Structures cannot have unitialized members.
Classes can.

Structures also have default constructor added by compiler so when you adding :this() as default constructor call, error with message that struct cannot have
uninitialized members disapper as default constructor will assign default values to members.

When you change to class, as they can have such members, error will also disappear.
 
Share this answer
 
Comments
FourCrate 15-Oct-12 19:36pm    
Thanks!
n.podbielski 16-Oct-12 1:09am    
No problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900