By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,768 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,768 IT Pros & Developers. It's quick & easy.

readonly fields

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.