readonly

Do not declare read only mutable reference types - why not?

柔情痞子 提交于 2019-12-10 01:16:39
问题 I have been reading this question and a few other answers and whilst I get the difference between changing the reference and changing the state of the current instance I'm not certain why this means that I shouldn't mark it readonly. Is this because marking something as readonly tells the compiler something special about the instance and so it is able to then treat it as thread safe when it actually might not be? Presumably there are situations where I don't want the instance to be able to be

Overriding ReadOnly Property in a subclass to make it Read/Write (VB.NET or C#)

百般思念 提交于 2019-12-09 18:15:15
问题 This doesn't seem possible in VB.NET with properties since the property statement itself must describe whether it is ReadOnly or not. In my example below, it doesn't let me make the ReadWriteChild compile. I guess I could make the parent Read/Write, and then have the ReadOnlyChild's setter not do anything, but that seems sort of hacky. The best alternative seems to be abandoning properties in favor of getter/setter methods in this case. Public MustInherit Class Parent Public MustOverride

Read-only array in .NET

旧时模样 提交于 2019-12-09 01:01:59
问题 Arrays are a fast way to iterate through an unordered set of items, and it's often nice for them to be read-only. While exposing arrays with the `readonly' keyword is useless because the contents of the array can still be altered, a ReadOnlyCollection<T> wrapper solves this. The problem is it's 4 times slower than a plain array in tests I've done. (I know, returning a copy of the array would only take a performance hit once, but ideally I wouldn't want to waste CPU time on that either.) I

Having a permanent value in an input field while still being able to add text to it

淺唱寂寞╮ 提交于 2019-12-08 22:22:22
问题 I don't know if this is possible but I would like to have an input field where I would have a value that is not editable by the user. However, I don't want the input field to be "readonly" because I still want the user to be able to add text after the value. If you have any idea on how to do this, let me know please that would help me a lot. EDIT: I use html forms. 回答1: You can position the text on top of the input field to make it look as if it is inside it. Something like this: <input type=

How to implement read-only ContentProvider?

こ雲淡風輕ζ 提交于 2019-12-08 21:15:13
问题 I am wondering how to best implement a read-only ContentProvider. I want my data source to be modified only from within my own application through additional special methods of my ContentProvider (which of course are not accessible through a ContentResolver). In other words, other applications should only be able to use my ContentProvider's query method but not insert, delete, or update. The obvious solution seems to be to just return null/0/0 and do nothing else in insert/delete/update.

jQuery Date Picker where text input is read only

家住魔仙堡 提交于 2019-12-08 18:48:19
问题 I want to use the Jquery datepicker. I've got it setup using an the alt field option. I'm displaying D/M/Y in the text field, but submitting Y-M-D. Everything works fine so far, sending the correct data, etc. However I want to stop the user from being able to manually type a date. I had originally set the INPUT field to disabled, which worked in every browser except IE. In IE it would popup the date picker but then not close after clicking a date. Does anyone know the best way to do this? 回答1

Decimal.MinValue & Decimal.MaxValue: why static readonly and not const modifiers?

扶醉桌前 提交于 2019-12-08 17:45:21
问题 In C#, MinValue field is defined for numeric types with: ① static readonly modifiers for decimal type (Link to MSDN Libray for .NET 4.5): public static readonly decimal MinValue ② const modifier for all other numeric types: //Integral signed numeric types public const sbyte MinValue public const short MinValue public const int MinValue public const long MinValue //Integral unsigned numeric types public const byte MinValue public const ushort MinValue public const uint MinValue public const

Why is there no IsReadOnlyChanged event on TextBox controls?

隐身守侯 提交于 2019-12-08 07:54:21
问题 I was adding some workaround code to fix the bug outlined in Is this a bug in DotNet 4 WPF Spell Checking?, (When a WPF TextBox changes Enabled, Visible or ReadOnly states, any SpellCheck custom dictionaries get dropped off until you disable and re-enable SpellCheck) and the simplest fix seemed to be to handle the IsVisibleChanged , IsEnabledChanged , and IsReadOnlyChanged events. Simple, right? Except there is no IsReadOnlyChanged event. Anybody know why and what the best way to trap a

Displaying read-only forms (values are shown as text instead of disabled input controls) with JSF?

一个人想着一个人 提交于 2019-12-08 04:45:06
问题 I have a data entry form where user enters lots of data. When user comes to the page to view existing data, the page should be displayed in read-only mode (all values shown as text), when he clicks 'Edit' button, normal form with all input controls should be shown so that user can change and save data. We are using JSF 2.0 with PrimeFaces library. It is easy to achieve above behavior for text box and text area but not for Checkbox, multi-select, radio,..... controls. Is there any easy way

Modify private readonly member variable?

大兔子大兔子 提交于 2019-12-08 01:20:45
问题 I have the following code : public class MyClass { private readonly string name; public string Name { get { return name; } } public MyClass(string name) { this.name = name; } } class Program { static void Main(string[] args) { MyClass mc = new MyClass("SomeName"); } } Is there any way I can change the value of mc.name without modifying the class? 回答1: You can only use reflection typeof(MyClass) .GetField("name",BindingFlags.Instance|BindingFlags.NonPublic) .SetValue(myclassInstance, 123); 回答2