Click here to Skip to main content
Rate this: bad
good
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 13:45pm
Edited 15-Oct-12 13:54pm
v5
Comments
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
good
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.
  Permalink  
Comments
FourCrate at 15-Oct-12 19:36pm
   
Thanks!
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 431
1 Afzaal Ahmad Zeeshan 184
2 /\jmot 176
3 Sergey Alexandrovich Kryukov 175
4 Marcin Kozub 175
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
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