Why isn’t String.Empty a constant?
In .NET why is String.Empty read only instead of a constant? I’m just wondering if anyone knows what the reasoning was behind that decision. 4 Answers 4
In .NET why is String.Empty read only instead of a constant? I’m just wondering if anyone knows what the reasoning was behind that decision. 4 Answers 4
I would like to show a radio button, have its value submitted, but depending on the circumstances, have it not editable. Disabled doesn’t work, because it doesn’t submit the value (or does it?), and it grays out the radio button. Read-only is really what I’m looking for, but for some mysterious reason it doesn’t work. … Read more
What are the benefits of having a member variable declared as read only? Is it just protecting against someone changing its value during the lifecycle of the class or does using this keyword result in any speed or efficiency improvements? 14 Answers 14
In a Django form, how do I make a field read-only (or disabled)? When the form is being used to create a new entry, all fields should be enabled – but when the record is in update mode some fields need to be read-only. For example, when creating a new Item model, all fields must … Read more
Is it possible to write something similar to the following? public const string[] Titles = { “German”, “Spanish”, “Corrects”, “Wrongs” }; 16 s 16 Yes, but you need to declare it readonly instead of const: public static readonly string[] Titles = { “German”, “Spanish”, “Corrects”, “Wrongs” }; The reason is that const can only be … Read more
What is the difference between const and readonly in C#? When would you use one over the other? 3 31