473,396 Members | 2,070 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,396 software developers and data experts.

is partial property implementation possible?

The C# Language Specification says:

A virtual property declaration specifies that the accessors of the property
are virtual. The virtual modifier applies to both accessors of a read-write
property - it is not possible for only one accessor of a read-write property
to be virtual.

An abstract property declaration specifies that the accessors of the
property are virtual, but does not provide an actual implementation of the
accessors. Instead, non-abstract derived classes are required to provide
their own implementation for the accessors by overriding the property.
Because an accessor for an abstract property declaration provides no actual
implementation, its accessor-body simply consists of a semicolon.

Does this mean it is possible for only one accessor of a read-write property
to be abstract (both get and set are virtual)?

I tried:

interface A
{
int X { get; set; }
}
abstract class B : A
{
virtual public int X
{
get
{
return 0;
}
}
}
class C : B
{
override public int X
{
// use base class getter
set
{
throw new Exception("Illegally tried to set X.");
}
}
}

But no matter omit the setter in abstract class B, leave it empty, try to
use the abstract keyword, I always get an error. I know I can use an
abstract member function for this, but how can I leave the setter undefined
(since B is abstract after all)?
Mar 23 '06 #1
2 9741

"Ben Voigt" <bv****@nospam.nospam> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
| The C# Language Specification says:
|
| A virtual property declaration specifies that the accessors of the
property
| are virtual. The virtual modifier applies to both accessors of a
read-write
| property - it is not possible for only one accessor of a read-write
property
| to be virtual.
|
| An abstract property declaration specifies that the accessors of the
| property are virtual, but does not provide an actual implementation of the
| accessors. Instead, non-abstract derived classes are required to provide
| their own implementation for the accessors by overriding the property.
| Because an accessor for an abstract property declaration provides no
actual
| implementation, its accessor-body simply consists of a semicolon.
|
|
|
|
|
| Does this mean it is possible for only one accessor of a read-write
property
| to be abstract (both get and set are virtual)?
|
| I tried:
|
| interface A
| {
| int X { get; set; }
| }
| abstract class B : A
| {
| virtual public int X
| {
| get
| {
| return 0;
| }
| }
| }
| class C : B
| {
| override public int X
| {
| // use base class getter
| set
| {
| throw new Exception("Illegally tried to set X.");
| }
| }
| }
|
|
|
| But no matter omit the setter in abstract class B, leave it empty, try to
| use the abstract keyword, I always get an error. I know I can use an
| abstract member function for this, but how can I leave the setter
undefined
| (since B is abstract after all)?
|
|

If you mean:
set{}
by " leave it empty"?

this should work.
Willy.

Mar 23 '06 #2
It appears that the compiler will not allow you to implement "half" of
an interface property. You must either declare it "abstract," in which
case you can define neither the getter nor the setter:

public abstract int X { get; set; }

or you must declare it "virtual," in which case it can have no abstract
component and you must define both the getter and the setter:

public virtual int X
{
get { ... }
set { ... }
}

There appears to be no way to implement the getter but require that
derived classes implement the setter.

Mar 23 '06 #3

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

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
4
by: Erik Wikström | last post by:
In school (no I will not ask you to do my schoolwork for me) we talked about policy-based design and got an assignment where we got the a code- fragment from a stack-implementation. The idea with...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
16
by: Madhuri Mittal | last post by:
Hi, I know that we can define a class over multiple source files using the keyword 'Partial' in C# within a project. Can we define the class over multiple projects using the 'Patial' keyword- I...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
9
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
2
by: Hiten | last post by:
Is it possible to have more code behind file but that file will have same class in way of partial class, Default Structure I -------------- Homepage.aspx + Homepage.aspx.cs (this .cs file...
1
by: daokfella | last post by:
I want to extend the auto-generated tableadapter classes created by the dataset designer. I'd like to add a connectionString property so I can set this outside my class library. I've got Get/Set...
10
by: JDeats | last post by:
So I have a class that spans over two partial classes in code, here's an example (do not read much into this, the code is of no practical use, this is just a simple example of where my confusion...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.