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

readonly significance?

In C#, what is the difference between a property block that has a readonly
keyword and a get block, versus a property block that has only a get block?

Thanks,
Jon

Nov 16 '05 #1
4 1214
The difference is that the one with just a get will compile ;-).

AFAIK readonly can only be applied to fields

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In C#, what is the difference between a property block that has a readonly
keyword and a get block, versus a property block that has only a get block?

Thanks,
Jon

Nov 16 '05 #2
the difference is that the one with readonly won't compile. readonly can
only be set on the field, but not the property.

"Jon Davis" wrote:
In C#, what is the difference between a property block that has a readonly
keyword and a get block, versus a property block that has only a get block?

Thanks,
Jon

Nov 16 '05 #3
Now if you're asking whats the difference between Foo and Bar in this example

class Quux
{
public int readonly Foo;
private int bar;
public int Bar
{
get{ return bar;}
}
}

the difference is Foo can only be set by the Quux constructor code (or a field initializer). Bar can only be read by clients of Quux, but the value it delivers can be changed by Quux any time it sees fit.

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

The difference is that the one with just a get will compile ;-).

AFAIK readonly can only be applied to fields

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In C#, what is the difference between a property block that has a readonly
keyword and a get block, versus a property block that has only a get block?

Thanks,
Jon
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.796 / Virus Database: 540 - Release Date: 13/11/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #4
That explains everything. Thank you very much.

Jon
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
message news:Ox**************@TK2MSFTNGP14.phx.gbl...
Now if you're asking whats the difference between Foo and Bar in this example
class Quux
{
public int readonly Foo;
private int bar;
public int Bar
{
get{ return bar;}
}
}

the difference is Foo can only be set by the Quux constructor code (or a field initializer). Bar can only be read by clients of Quux, but the value
it delivers can be changed by Quux any time it sees fit.
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

The difference is that the one with just a get will compile ;-).

AFAIK readonly can only be applied to fields

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In C#, what is the difference between a property block that has a readonly keyword and a get block, versus a property block that has only a get block?
Thanks,
Jon
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.796 / Virus Database: 540 - Release Date: 13/11/2004

[microsoft.public.dotnet.languages.csharp]

Nov 16 '05 #5

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

Similar topics

2
by: Darshak Shah | last post by:
Hi, * Question background : My DB is in ArchiveLog mode. I have TS in ReadOnly mode. As i know, - Oracle allows to DROP table resides in ReadOnly TS (& other objects also) even though that...
4
by: harry | last post by:
<input type="text" name="actreqto" maxlength="20" value="" onkeypress="changedDetails();" onchange="changedDetails();" readonly="readonly"> Any ideas why doesn't this work? ...
3
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and...
4
by: Prem Mallappa | last post by:
Hello can anybody please tell me what is the significance of 0; 1; or something like 100;
3
by: Michael SL | last post by:
I have a text area in which I have a client side javascript to process a "onclick". Because it is client side, I used a HtmlTextArea <TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH:...
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...
3
by: Jon Davis | last post by:
What is the difference between a Property block that has a ReadOnly keyword and a Get block, versus a Property block that has only a Get block? Thanks, Jon
10
by: sunil | last post by:
Hello, I am new to c# . I have some basic programming doubts. Please help me in clarifying these doubts. I want to initialize a static and readonly field with a value returned by a static...
26
by: joe | last post by:
My experiments show that the random number generator in Microsoft's VC++6 compiler is a statistical RNG with a significance level 1.0%. Statistical testing at SL >1.0% (for example 1.001%) passes...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.