Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

getter/setter with no body

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kronrn@yahoo.com - 19 Aug 2006 17:29 GMT
Hi Folks

Can anyone confirm that the code

public string Name
{
get;
set;
}

is used to define an abstract property accessor?

would I also need to use the abstract keyword eg

public abstract string Name
{
get;
set;
}

Many Thanks

Kron
Nicholas Paldino [.NET/C# MVP] - 19 Aug 2006 17:57 GMT
Kron,

   Have you tried it and compiled it?

public string Name {get; set;}

   The above will not work.  The compiler expects an implementation to the
property.

public abstract string Name {get; set;}

   The above will work.  It will require derived classes to override the
implementation.

   If you want to provide a default implementation which can be overriden,
then you can use virtual:

public virtual string Name
{
   get
   {
       return name;
   }
   set
   {
       name = value;
   }
}

   Hope this helps.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi Folks
>
[quoted text clipped - 19 lines]
>
> Kron
kronrn@yahoo.com - 19 Aug 2006 18:17 GMT
Thanks Nicholas, your answer is most helpful :)

I played around with this after I posted and found the results to be
exactly as you say. Next time I'll try it out first ;)

Many Thanks

Kron

> Kron,
>
[quoted text clipped - 54 lines]
> >
> > Kron
Philip Daniels - 19 Aug 2006 19:08 GMT
>Kron,
>
[quoted text clipped - 4 lines]
>    The above will not work.  The compiler expects an implementation to the
>property.

Yep, but if you drop the "public" it will work in an interface, it's
the syntax for specifying a property member. (I am sure you knew this
but maybe not the O.P...)

--
Philip Daniels
Nicholas Paldino [.NET/C# MVP] - 21 Aug 2006 02:23 GMT
Philip,

   If you drop off the public, then it is assumed to be private.  You still
get a compiler error.  It doesn't assume abstract when there is no public
access modifier.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>>Kron,
>>
[quoted text clipped - 12 lines]
> --
> Philip Daniels
Carl Daniel [VC++ MVP] - 21 Aug 2006 02:37 GMT
> Philip,
>
>    If you drop off the public, then it is assumed to be private.  You
> still get a compiler error.  It doesn't assume abstract when there is
> no public access modifier.

... unless it's in an interface definition, as the previous poster said.

-cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.