473,804 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6245
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.co m

<kr****@yahoo.c omwrote in message
news:11******** **************@ 74g2000cwt.goog legroups.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.co m

<kr****@yahoo.c omwrote in message
news:11******** **************@ 74g2000cwt.goog legroups.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.c omwrote:
>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.co m

"Philip Daniels" <fo*@foo.comwro te in message
news:cp******** *************** *********@4ax.c om...
On Sat, 19 Aug 2006 12:57:39 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omwrote:
>>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
18091
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 getters and setters when needed. But most of getter/setter pairs I have seen are just like below; > private int x; > public int getX() { return x; } > public void setX(int x) { this.x = x; }
4
5545
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 property does some data manipulation before it returns the value. I wanted to add another getter to this property that would returnt the "Raw" value (what is stored in _name). Example:
1
1926
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 running the client. public class MyFeeResponse {
12
3745
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 cannot figure out where the problem is actually occurring. The first couple of lines of my code behind: Partial Class _Default
6
3516
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 best practices for implementing versioning for changing properties? Thanks
3
99397
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
1411
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 seems to be working fine, except for when the class has a property with only getter (no setter), it freaks out, and returns the following
0
1195
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
2517
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 would be greatly appreciated!! Question: Write a class called shapes that accepts two variables into its constructor called a and b. Along with the getter and setter methods required, write a method called toPrinter() to output the coordinates of...
2
3119
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 System.Web.UI.WebControls.TextBox.Text property is set'd or get'd. I'm aware there are things I can do such as wrap this control, but for political reasons, I need to try to come up with a solution that will involve changing or adding as little code as...
0
10562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10070
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.