locked
must declare a body because it is not marked abstract, extern, or partial

    Question

  • I get following errors :
    Error 1 'Project.Shape.X.get' must declare a body because it is not marked abstract or extern
    Error 2 'Project.Shape.X.set' must declare a body because it is not marked abstract or extern
    Error 3 'Project.Shape.Y.get' must declare a body because it is not marked abstract or extern
    Error 4 'Project.Shape.Y.set' must declare a body because it is not marked abstract or extern
    Error 5 'Project.Shape.Height.get' must declare a body because it is not marked abstract or extern
    Error 6 'Project.Shape.Height.set' must declare a body because it is not marked abstract or extern
    Error 7 'Project.Shape.Width.get' must declare a body because it is not marked abstract or extern
    Error 8 'Project.Shape.Width.set' must declare a body because it is not marked abstract or extern
    Can you help me solv this problem please...
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace Project
    {
        public  class Shape
        {
            public int X { get; private set; }
            public int Y { get; private set; }
            public int Height { get; set; }
            public int Width { get; set; }
            public virtual void Draw()
            {
                Console.WriteLine("Performing base class drawing tasks");
            }
        }
        class Circle : Shape
        {
            public override void Draw()
            {
                Console.WriteLine("Drawing a circle");
                base.Draw();
            }
        }
        class Rectangle : Shape
        {
            public override void Draw()
            {
                Console.WriteLine("Drawing a rectangle");
                base.Draw();
            }
        }
        class Triangle : Shape
        {
            public override void Draw()
            {
                
                Console.WriteLine("Drawing a triangle");
                base.Draw();
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                
                System.Collections.Generic.List<Shape> shapes = new System.Collections.Generic.List<Shape>();
                shapes.Add(new Rectangle());
                shapes.Add(new Triangle());
                shapes.Add(new Circle());
                
                foreach (Shape s in shapes)
                {
                    s.Draw();
                }
               
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
     
    }
    Sunday, June 26, 2011 10:23 AM

Answers

  • Hi,

    tested your code, it runs fine here. Maybe rebuild your application...

    Regards,

      Thorsten

    • Marked as answer by megibyan Sunday, June 26, 2011 11:01 AM
    Sunday, June 26, 2011 10:48 AM
  • Hi,

    Do you use VS 2010 ? Could it be just that you are using an older compiler that doesn't have yet support for autoimplemented properties ?

    If using VS 2010, what if you try in a new project (either something is wrong with VS, or something is wrong with this particular project).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by megibyan Sunday, June 26, 2011 11:01 AM
    Sunday, June 26, 2011 10:58 AM
  • Automatic properties are available starting with VS 2008. So either you'll have to change your code to implement explicitely those properties or you could consider switching to a more recent version.

     For the former :

      int _X;
          public int X {
            get
            {
              return _X;
            }
            private set
            {
              _X=value;
            }
          }
    

    When in doubt, please always start by looking at the doc. For example http://msdn.microsoft.com/en-us/library/bb384054.aspx shows you need VS 2008 or 2010...

     

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by megibyan Monday, July 04, 2011 10:11 AM
    Sunday, June 26, 2011 11:30 AM
  • Automatic properties did not arrive in visual studio until VS 2008 (c# 3.0).  You need to do it the old way in VS 2005:
     
     
    private int _x, _y;
    public int X {get {return _x;} set {_x = value;}}
    public int Y{get {return _y;} set {_y = value;}}

    --
    Mike
    • Marked as answer by megibyan Monday, July 04, 2011 10:12 AM
    Sunday, June 26, 2011 11:35 AM

All replies

  • Hi,

    tested your code, it runs fine here. Maybe rebuild your application...

    Regards,

      Thorsten

    • Marked as answer by megibyan Sunday, June 26, 2011 11:01 AM
    Sunday, June 26, 2011 10:48 AM
  • Hi,

    Can the problem be in compiling it on 2005?

     

    Regard,

    Mike

    Sunday, June 26, 2011 10:51 AM
  • Hi,

    Do you use VS 2010 ? Could it be just that you are using an older compiler that doesn't have yet support for autoimplemented properties ?

    If using VS 2010, what if you try in a new project (either something is wrong with VS, or something is wrong with this particular project).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by megibyan Sunday, June 26, 2011 11:01 AM
    Sunday, June 26, 2011 10:58 AM
  • I use VS 2005
    Sunday, June 26, 2011 11:01 AM
  • Do I need to change my VS from 2005 to 2010?
    Sunday, June 26, 2011 11:09 AM
  • Automatic properties are available starting with VS 2008. So either you'll have to change your code to implement explicitely those properties or you could consider switching to a more recent version.

     For the former :

      int _X;
          public int X {
            get
            {
              return _X;
            }
            private set
            {
              _X=value;
            }
          }
    

    When in doubt, please always start by looking at the doc. For example http://msdn.microsoft.com/en-us/library/bb384054.aspx shows you need VS 2008 or 2010...

     

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by megibyan Monday, July 04, 2011 10:11 AM
    Sunday, June 26, 2011 11:30 AM
  • Automatic properties did not arrive in visual studio until VS 2008 (c# 3.0).  You need to do it the old way in VS 2005:
     
     
    private int _x, _y;
    public int X {get {return _x;} set {_x = value;}}
    public int Y{get {return _y;} set {_y = value;}}

    --
    Mike
    • Marked as answer by megibyan Monday, July 04, 2011 10:12 AM
    Sunday, June 26, 2011 11:35 AM
  • Thank's everyone, I solved the problem.

    Regard,

    Mike.

    Monday, July 04, 2011 10:13 AM