473,383 Members | 1,805 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,383 software developers and data experts.

-- or ++ operators on ReadOnly property

if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the
value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.
Nov 15 '05 #1
7 2129
Sacha Faust <sf****@spidynamics.com> wrote:
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the
value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.


No.

Essentially, --PropertyName is:

(PropertyName=PropertyName-1) with the result being the already
decremented version.

What did you want --(string.Length) to actually achieve? Could you give
an example of where you'd use it?

See section 14.6.5 of the ECMA C# spec for more details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
100
Hi Sacha,
-- and ++ requires *l-value* in other words it needs storage location,
property or indexer because it changes the value kept on it
Those operators cannot be applied on constants.
If you want to decrement the value returned by that property simply do

int a = obj.Prop - 1;

HTH
B\rgds
100

"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:eY*************@tk2msftngp13.phx.gbl...
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the
value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.

Nov 15 '05 #3
You want to use 'stringVar.Length - 1' and get more sleep ;)

x = --variable; // Same as variable = variable - 1; x = variable;
x = variable--; // Same as x = variable; varaible = variable - 1;
x = ++variable; // Same as variable = variable + 1; x = variable;
x = variable++; // Same as x = variable; variable = variable + 1;

Tom Clement
Apptero, Inc.
"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:eY*************@tk2msftngp13.phx.gbl...
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the
value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.

Nov 15 '05 #4
logically
--variable and --(variable) should be different.

I think that the LValue explains some of the issue.
"Tom Clement" <To***********@Apptero.com> wrote in message
news:uS*************@TK2MSFTNGP11.phx.gbl...
You want to use 'stringVar.Length - 1' and get more sleep ;)

x = --variable; // Same as variable = variable - 1; x = variable;
x = variable--; // Same as x = variable; varaible = variable - 1;
x = ++variable; // Same as variable = variable + 1; x = variable;
x = variable++; // Same as x = variable; variable = variable + 1;

Tom Clement
Apptero, Inc.
"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:eY*************@tk2msftngp13.phx.gbl...
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.


Nov 15 '05 #5
Sacha Faust <sf****@spidynamics.com> wrote:
logically
--variable and --(variable) should be different.


I don't see why. What would you expect --(variable) to do differently?
Again, could you give an example of how you'd expect to use it?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Good point. I wasn't paying close enough attention to your original post.
It is true that (variable) is not an lvalue, as Jon pointed out, and so
cannot be modified.
Sorry for my misunderstanding.

Tom Clement
Apptero, Inc.
"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
logically
--variable and --(variable) should be different.

I think that the LValue explains some of the issue.
"Tom Clement" <To***********@Apptero.com> wrote in message
news:uS*************@TK2MSFTNGP11.phx.gbl...
You want to use 'stringVar.Length - 1' and get more sleep ;)

x = --variable; // Same as variable = variable - 1; x = variable;
x = variable--; // Same as x = variable; varaible = variable - 1;
x = ++variable; // Same as variable = variable + 1; x = variable;
x = variable++; // Same as x = variable; variable = variable + 1;

Tom Clement
Apptero, Inc.
"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:eY*************@tk2msftngp13.phx.gbl...
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify the value of the readonly property.

From my understanding, the -- operator should be decrementing the value return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.



Nov 15 '05 #7
Sacha Faust wrote:
logically
--variable and --(variable) should be different.

I think that the LValue explains some of the issue.

Parentheses do not change whether an expression is an l-value or not.
This is the case in C, C++, and C#. It may be different in other languages.

If you look carefully at the language specs for each of these languages,
an expression surrounded by parentheses does not create a new object -
the type and value are identical to what is inside the parentheses.


"Tom Clement" <To***********@Apptero.com> wrote in message
news:uS*************@TK2MSFTNGP11.phx.gbl...
You want to use 'stringVar.Length - 1' and get more sleep ;)

x = --variable; // Same as variable = variable - 1; x = variable;
x = variable--; // Same as x = variable; varaible = variable - 1;
x = ++variable; // Same as variable = variable + 1; x = variable;
x = variable++; // Same as x = variable; variable = variable + 1;

Tom Clement
Apptero, Inc.
"Sacha Faust" <sf****@spidynamics.com> wrote in message
news:eY*************@tk2msftngp13.phx.gbl...
if you have a ready only properly like string.Length and I do
--(string.Length) I get a compiler problem saying that I can't modify
the
value of the readonly property.

From my understanding, the -- operator should be decrementing the value
return by (string.Lenght) and not string.Lenght directly.

Am I right or just completely wrong on this and should get more sleep.
If I'm wrong can you give details.

Tks.




--
mikeb
Nov 15 '05 #8

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

Similar topics

10
by: GP | last post by:
Is it possible to iterate through all the controls collection and make the textboxes alone as read only.I don't see a readonly property for the Control.Can some one help me in this context? I...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
2
by: Marcin Floryan | last post by:
I am creating a custom control (Inherits UserControl) and my control containt a TextBox control. TextBox control has a Property called "ReadOnly". I would like to expose this property outside my...
7
by: DareDevil | last post by:
I have written a method that should modify the folder path passed to it into one that exists and is selected by the user. It then returns a boolean depending on whether a folder path was selected by...
3
by: Tom | last post by:
I'm using the PropertyGrid, and have it bound to a class object. Works fine - however, I have some properties that I want to show up on the grid (i.e. they are browsable) -YET- I don't want the...
1
by: Jumping Matt Flash | last post by:
I'm trying to achieve a property within a class which returns a conditional result dependent on the class members values. I will explain.. Public Class Address Private addrCountry As String...
2
by: miben | last post by:
I need to set a variable returned by a readonly property in a class by another class. So the only way to set that value is from a specific class and function. Public Sub Main Dim setter As New...
6
by: Roberto | last post by:
Hi, using vb 2005 I'd like to have a combobox in READONLY mode, like I have for textbox. Combobox only has enabled property. When I turn this property false I can not select the text in the...
0
by: Tom Dacon | last post by:
Oops, what I gave you in my first response was the usual way that you use varying scope: Private _FieldValue As <some type> Public Property Something As <some type> Get Return _FieldValue...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
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...

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.