tagged [readonly]
Set readonly fields in a constructor local function c#
Set readonly fields in a constructor local function c# The following does not compile. It fails with this error: > CS0191 A readonly field cannot be assigned to (except in a constructor or a variable ...
- Modified
- 15 Mar at 13:26
CheckBoxField columns in ASP.NET GridView are disabled even if ReadOnly set to false
CheckBoxField columns in ASP.NET GridView are disabled even if ReadOnly set to false I have a GridView with two CheckBoxField columns. They both have ReadOnly property set to false, but html code gene...
Why can't I initialize readonly variables in a initializer?
Why can't I initialize readonly variables in a initializer? Why can't I initialize readonly variables in a initializer? The following doesn't work as it should: Is this due to some technical limits of...
- Modified
- 16 Dec at 19:0
assign value of readonly variable in private method called only by constructors
assign value of readonly variable in private method called only by constructors C# compiler gave me the following error CS0191: A readonly field cannot be assigned to (except in a constructor or a var...
- Modified
- 27 Jul at 17:38
Property or indexer cannot be assigned to "--" it is read only
Property or indexer cannot be assigned to "--" it is read only So I'm trying to pass a local string to another form in a c# project. This is my code: Form 1: Form 2 I'm getting the error: > Property o...
C# and immutability and readonly fields... a lie?
C# and immutability and readonly fields... a lie? I have found that People claim that using all readonly fields in a class does not necessarily make that class's instance immutable because there are "...
- Modified
- 18 Jul at 17:36
How to Setup a readonly property with Moq?
How to Setup a readonly property with Moq? I am trying to unit test using Moq. Here is the example code: ``` public class ConcreteClass { private readonly FirstPropery firstProperty; private reado...
- Modified
- 20 Apr at 09:53
C# return a variable as read only from get; set;
C# return a variable as read only from get; set; I swear I have seen an example of this but have been googling for a bit and can not find it. I have a class that has a reference to an object and need ...
- Modified
- 2 Jun at 13:37
How can a readonly static field be null?
How can a readonly static field be null? So here's an excerpt from one of my classes: As you can see, it's a singleton-per-thread - i.e. the instance is marked with
- Modified
- 11 Jan at 17:12
Declaring a const double[] in C#?
Declaring a const double[] in C#? I have several constants that I use, and my plan was to put them in a const array of doubles, however the compiler won't let me. I have tried declaring it this way: T...
Why is this field declared as private and also readonly?
Why is this field declared as private and also readonly? In the following code: ``` public class MovieRepository : IMovieRepository { private readonly IHtmlDownloader _downloader; public MovieRepo...
Why does ReSharper prefer consts over readonly?
Why does ReSharper prefer consts over readonly? I've noticed ReSharper suggestion under "Common Practices and Code Improvements": . I've also noticed that in Bill Wagner's book "[Effective C#: 50 Spec...
How should I use properties when dealing with read-only List<T> members
How should I use properties when dealing with read-only List members When I want to make a value type read-only outside of my class I do this: What can I do to make a `List` type readonly (so they can...
- Modified
- 9 Aug at 00:9
Static readonly vs const — different assemblies POV?
Static readonly vs const — different assemblies POV? There are many questions about this subject , but none (except [one but still a short one](https://stackoverflow.com/questions/755685/c-static-read...
How to create an empty IReadOnlyCollection
How to create an empty IReadOnlyCollection I'm creating an extension method for [MultiValueDictionary](http://blogs.msdn.com/b/dotnet/archive/2014/08/05/multidictionary-becomes-multivaluedictionary.as...
- Modified
- 10 Aug at 09:46
How to keep the Text of a Read only TextBox after PostBack()?
How to keep the Text of a Read only TextBox after PostBack()? I have an ASP.NET `TextBox` and I want it to be `ReadOnly`. (The user modify it using another control) But when there is a `PostBack()`, T...
const vs. static readonly
const vs. static readonly > [What is the difference between const and readonly?](https://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly) So from what I read, in ...
How do I set a readonly field in an initialize method that gets called from the constructor?
How do I set a readonly field in an initialize method that gets called from the constructor? I'm sure I've seen somewhere that I can do the following by using an attribute above my Init() method, that...
- Modified
- 16 Sep at 15:58
Is a readonly field in C# thread safe?
Is a readonly field in C# thread safe? Is a `readonly` field in C# thread safe? Have gone through some posts: - [What are the benefits to marking a field
- Modified
- 21 May at 17:0
Why IReadOnlyCollection has ElementAt but not IndexOf
Why IReadOnlyCollection has ElementAt but not IndexOf I am working with a `IReadOnlyCollection` of objects. Now I'm a bit surprised, because I can use `linq` extension method `ElementAt()`. But I don'...
- Modified
- 23 May at 11:44
readonly-fields as targets from subclass constructors
readonly-fields as targets from subclass constructors A readonly field should be used when you have a variable that will be known at object-instatiation which should not be changed afterwards. However...
- Modified
- 9 Oct at 20:41
ReadOnlyCollection or IEnumerable for exposing member collections?
ReadOnlyCollection or IEnumerable for exposing member collections? Is there any reason to expose an internal collection as a ReadOnlyCollection rather than an IEnumerable if the calling code only iter...
- Modified
- 29 Jan at 12:20
What does immutable and readonly mean in C#?
What does immutable and readonly mean in C#? Is it correct that it is not possible to change the value of an immutable object? I have two scenarios regarding `readonly` that I want to understand: 1. W...
- Modified
- 27 Jul at 18:36
Converting Dictionary<TKey, List<TValue>> to ReadOnlyDictionary<TKey, ReadOnlyCollection<TValue>>
Converting Dictionary> to ReadOnlyDictionary> I have a dictionary as follows: Now I want to be
- Modified
- 1 Mar at 21:44
"Read only" Property Accessor in C#
"Read only" Property Accessor in C# I have the following class: I want users to be able to get mMyList which is why i exposed the "get" via a property however i don't want changes they make to the obj...
- Modified
- 30 Aug at 20:54