Click here to Skip to main content
11,703,632 members (64,373 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# struct
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 15-Oct-12 12:45pm
Edited 15-Oct-12 12:54pm
n.podbielski at 15-Oct-12 19:18pm
"I am getting squiggly error lines."

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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
FourCrate at 15-Oct-12 19:36pm
n.podbielski at 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)

  Print Answers RSS
0 OriginalGriff 550
1 Maciej Los 530
2 Sergey Alexandrovich Kryukov 381
3 Andy Lanng 294
4 CPallini 195
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100