3 Replies - 1013 Views - Last Post: 18 March 2010 - 12:46 AM Rate Topic: -----

#1 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 112
  • Joined: 17-March 10

Problem with get set properties...

Posted 17 March 2010 - 06:05 AM

Hi there Gurus!

Can anybody tell me why can't i create Get Set properties using this syntax?

public class Customer
{
    public int ID { get; set; }
    public string Name { get; set; }
}



Brackets after get and set won't help either.

it gives: "ReadOnlyProperty.Customer.ID.get' must declare a body because it is not marked abstract or extern"
Marking them abstract or extern won't help either.

I know that this would do the job:

public int ID
        {
            get
            {
                return m_id;
            }
            set
            {
                m_id = value;
            }
        }

        public string Name
        {
            get
            {
                return m_name;
            }
            set
            {
                m_name = value;
            }
        }



I read from the book that the first one is possible to implement.
Am i missing something?


Thanks in advance,
and don't forget... C sharp, think sharp :)

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with get set properties...

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 380
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Problem with get set properties...

Posted 17 March 2010 - 06:22 AM

What version of Visual Studio are you using? I believe this syntax is available only in VS2008 and higher...
Was This Post Helpful? 1
  • +
  • -

#3 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 112
  • Joined: 17-March 10

Re: Problem with get set properties...

Posted 18 March 2010 - 12:09 AM

Thanks a lot FlashM!

That solved the problem. I have VS2005.
Hey, this was my first post and i already got the answer for my problem... I like this forum.

Best Regards,
c#think#.
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 380
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Problem with get set properties...

Posted 18 March 2010 - 12:46 AM

Nice to hear that. Hope you'll enjoy being part of the DreamInCode community.

Happy coding...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1