473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

getter/setter with no body

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

Aug 19 '06 #1
5 6211
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<kr****@yahoo.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
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

Aug 19 '06 #2
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
Nicholas Paldino [.NET/C# MVP] wrote:
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<kr****@yahoo.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
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
Aug 19 '06 #3
On Sat, 19 Aug 2006 12:57:39 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comwrote:
>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.
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
Aug 19 '06 #4
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Philip Daniels" <fo*@foo.comwrote in message
news:cp********************************@4ax.com...
On Sat, 19 Aug 2006 12:57:39 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comwrote:
>>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.

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

Aug 21 '06 #5
Nicholas Paldino [.NET/C# MVP] wrote:
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
Aug 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kiwi | last post by:
Hello. I know a getter can return other thing than a field. I know a setter can do more things than setting a field. I know there are "setter only" cases and "getter only" cases. I do use...
4
by: Jimbo | last post by:
I am sort of new to C#. Currently have a private property called "_name" in a class. I have written a public getter and setter routine for it called "Name". Currently, the getter for the...
1
by: Steve | last post by:
I generate C# webservices proxy code from WSDL file, it turns out the classes generated have public member variables and no getter/setter methods as follows, and I am able to get data when...
12
by: Adam Sandler | last post by:
Hi all, I hope this is an easy one... Using VWD 2005. When I call my accessor method (getName) I always receive an empty string back. Debugging shows there should be something there but I...
6
by: Peter Franks | last post by:
Is it possible to deserialize a class that has a public property w/ a setter, but no getter? I'm not finding anything that would allow this -- Presuming that is is NOT possible, what are the...
3
by: Martin Pöpping | last post by:
Hello, I´m coming from the Java World. Here Programmers often use (like in C++?) getter and setter methods. F.e.: class Mirror{ private int width_;
2
by: Amie | last post by:
Hi, I have an atlas related question.. I have a web form that submits the information to a web service method, and it's done thru Atlas by binding the web methods to client functions. It...
0
by: shyamg | last post by:
Hi all i am newly add new Attribute "name" in strutshtml- tld file but its asking for setter method for attribute. where can add the setter and getter. Thanks. ss.
5
by: javatech007 | last post by:
Hi, I've been at this question all day and still just don't know what to do. It's the last of all the questions I have to do and can't figure it out!! If anyone could help or give guidance it...
2
by: Josh Valino | last post by:
Hi, Is there anyway that I can hook into a getter and setter of a property for a ..Net control across my application? Specifically, what I'd like to do is execute some code whenever a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.