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

readonly fields

It is possible to declare a class with a uninitialized readonly field
without compiler warning. Is this intended and if so, why?

public class Stuff
{
public readonly int a;
}

By definition, readonly fields can only be initialied inside a
constructor or within the declaration of the field.

I would even say that also for normal class fields there should be a
test that if nowhere in the class an assignment to that variable is
found, a warning should be produced. Of course this only applies only to
private and internal variables, otherwise also code outside the assembly
would be allowed to initialize the variable which cannot be determined
at compile time.
Sep 25 '07 #1
0 981

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

Similar topics

2
by: Fred K. | last post by:
Hi, I have form text fields that have the attribute readonly. I wish to use a javascript (invoked by a button on my page) to erase the values and set the readonly attribute to false. How do I...
10
by: William Stacey | last post by:
I know the following is not allowed, but shouldn't it be? sharedObject is part of Derived and should be able to be set in the constructor - no? tia public abstract class Base1 { protected...
19
by: cody | last post by:
Iam wondering what the benefit of using const over static readonly is. static readonly is a runtime constant and can be set once in the initializer or the static ctor, whereas const is suffering...
11
by: Christof Nordiek | last post by:
Hi all, Can there be a performance difference, if i use readonly fields instead of constants? e.g.: const int n = 100; vs. static readonly int = 100;
2
by: Amit | last post by:
Hello, I have a class where I store a lot of setting names. Right now they're all declared as consts : public const CurDoc as string = "CURRENT_DOCUMENT" From what I know about const, every...
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...
4
by: cody | last post by:
It is possible to declare and use/instantiate a class with a uninitialized readonly field without even a compiler warning. Why don't I get warnings? public class Stuff { public readonly int a;...
3
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I need to dynamically set the ReadOnly value in a BoundField in a DetailsView. The DetailsView is generated from a GridView selection and has both Edit and New buttons. I need to be able to set...
8
by: Weeble | last post by:
I was surprised to discover today that local variables can't be "readonly". (They can be "const", but that's only for compile-time constants, not something that might be calculated at run-time.) I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...
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...

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.