473,387 Members | 3,801 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,387 software developers and data experts.

One thing that I do not like about properties in C#

It would have been better if you had more control on the properties in C#:

class Foobar
{
int myFoo;

property int MyFoo
{
public get
{
return myFoo;
}

internal set
{
myFoo = value;
}
}
}

I have not yet looked at properties in C# 2.0, but I'm sure that this has
not yet been implemented.
Since those properties are translated into methods (get_MyFoo()
set_MyFoo() [weird, the D code below works fine without the ugliness of
get_ and set_ prefixes]), similar to the D code below, the only thing that
needs to be changed is the C# compiler to support this type of control.
In the D programming language, you do have something like this:

class Foobar
{
private int myFoo;

public int MyFoo()
{
return myFoo;
}// read property

protected void MyFoo(int value)
{
myFoo = value;
} // write property
}

To use it:

void main()
{
Foobar f;

put(f.MyFoo); // same as f.MyFoo();
f.MyFoo = 3; // same as f.MyFoo(3); error inaccessible
f.MyFoo + 3; // same as f.MyFoo(f.MyFoo() + 3); error inaccessible
}
Nov 16 '05 #1
2 1331
SpookyET <no****@hotmail.com> wrote:
It would have been better if you had more control on the properties in C#:
Agreed.

<snip>
I have not yet looked at properties in C# 2.0, but I'm sure that this has
not yet been implemented.
You're wrong - it has.

From http://msdn.microsoft.com/chats/vstu...dio_032103.asp

<quote>
Q: Will separate access specifiers for getting and setting properties
become a part of the language?

A: Regarding different accessibility of get and set assessors of a
property, yes, we will support that in the Whidbey release of C#.
</quote>
Since those properties are translated into methods (get_MyFoo()
set_MyFoo() [weird, the D code below works fine without the ugliness of
get_ and set_ prefixes]), similar to the D code below, the only thing that
needs to be changed is the C# compiler to support this type of control.


Actually, the CLR specs need to be changed to allow the getter and
setter to have different accessibility, too, if you care about being
CLS-compliant.

<quote>
CLS Rule 25: The accessibility of a property and of its accessors shall
be identical.
</quote>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

"SpookyET" <no****@hotmail.com> wrote in message
news:opr5827lst1s9n15@saturn...
It would have been better if you had more control on the properties in C#:

class Foobar
{
int myFoo;

property int MyFoo
{
public get
{
return myFoo;
}

internal set
{
myFoo = value;
}
}
}

I have not yet looked at properties in C# 2.0, but I'm sure that this has
not yet been implemented.
Since those properties are translated into methods (get_MyFoo()
set_MyFoo() [weird, the D code below works fine without the ugliness of
get_ and set_ prefixes]), similar to the D code below, the only thing that
needs to be changed is the C# compiler to support this type of control.
In the D programming language, you do have something like this:

class Foobar
{
private int myFoo;

public int MyFoo()
{
return myFoo;
}// read property

protected void MyFoo(int value)
{
myFoo = value;
} // write property
}

To use it:

void main()
{
Foobar f;

put(f.MyFoo); // same as f.MyFoo();
f.MyFoo = 3; // same as f.MyFoo(3); error inaccessible
f.MyFoo + 3; // same as f.MyFoo(f.MyFoo() + 3); error inaccessible
}


Personally I think this is a pretty bad design, over all. Without explicitly
defining something as a property you are just going on the hope that you
won't need that particular overload. That is probably enough to make me
refuse to use properties as properties in D. The get and set prefixes are
designed so that there would be no naming collisions. Almost no one ever
actually has to directly access get_ and set_ so there is really no
uglieness there.
get_ and set_ aren't absolutly required either, IIRC, but are strongly
recommended.

Anyway, C# indeed will have properties which can have different accessiblity
on there accessors
Nov 16 '05 #3

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

Similar topics

6
by: amethyste | last post by:
hello, This is my sample (simplified): public class Binom { public string _Value;
2
by: SpookyET | last post by:
It would have been better if you had more control on the properties in C#: class Foobar { int myFoo; property int MyFoo { public get {
13
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My...
1
by: Smoke | last post by:
Im sure i have asked this about 5 months ago, and someone sent me an interesting article about how to do what i need, but i lost it.. Im developing a custom control and i would need to have nested...
2
by: CJ Taylor | last post by:
You know, you can learn a lot about the datagrid control by just reading about it. =) BTW, Jan's Grid is amazing... Anyone paying hundreds of dollars for a grid, take the few minutes out to...
5
by: Versteijn | last post by:
Hello all, I have the following scheme: Class Customer Class Partner Inherits Customer Now, I have a customer, that wants to be a partner. A lot of methods and properties of my Customer...
4
by: Luke Matuszewski | last post by:
Here are some questions that i am interested about and wanted to here an explanation/discussion: 1. (general) Is the objectness in JavaScript was supported from the very first version of it (in...
17
by: Bruce One | last post by:
Lets consider a class called Currency. This class must be the responsible for taking care of all calculations over currency exchanges, in such a way that I pass values in Euros and it returns the...
1
by: Rich | last post by:
Hello, my project (vb2005) contains several classes that each produce lists of data which get stored/displayed in ado.net tables that have the same structure for each of the lists produced by...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
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
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...

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.