tagged [immutability]

How can I create a new instance of ImmutableDictionary?

How can I create a new instance of ImmutableDictionary? I would like to write something like this: (using `ImmutableDictionary` from [System.Collections.Immutable](http://www.nuget.org/packages/Micros...

11 Feb at 08:20

What is difference between mutable and immutable String in java

What is difference between mutable and immutable String in java As per my knowledge, a mutable string can be changed, and an immutable string cannot be changed. Here I want to change the value of Stri...

Does String.Replace() create a new string if there's nothing to replace?

Does String.Replace() create a new string if there's nothing to replace? For example: If I were to call "R

21 Nov at 01:28

How do I delete specific characters from a particular String in Java?

How do I delete specific characters from a particular String in Java? For example I'm extracting a text String from a text file and I need those words to form an array. However, when I do all that som...

27 May at 15:57

Is there a way to use Json.Net deserialization with immutable classes?

Is there a way to use Json.Net deserialization with immutable classes? I'm working with an API that uses json. I have some classes that I've created to model the API. To make life easy, my models use ...

31 Jan at 19:30

Immutable Data Structures in C#

Immutable Data Structures in C# I was reading some entries in Eric Lippert's blog about [immutable data structures](http://blogs.msdn.com/b/ericlippert/archive/tags/immutability/) and I got to thinkin...

14 Dec at 18:56

Efficient, Immutable, Extensible Collections for .NET

Efficient, Immutable, Extensible Collections for .NET It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside e...

24 Dec at 18:20

C#: Immutable view of a list's objects?

C#: Immutable view of a list's objects? I have a list, and I want to provide read-only access to a collection containing its contents. How can I do this? Something like: Additionally, an immutable `IE...

15 Apr at 23:26

Error: "Cannot modify the return value" c#

Error: "Cannot modify the return value" c# I'm using auto-implemented properties. I guess the fastest way to fix following is to declare my own backing variable? > Error Message: Cannot modify the ret...

6 Sep at 18:22

How to create immutable objects in C#?

How to create immutable objects in C#? In a question about [Best practices for C# pattern validation](https://softwareengineering.stackexchange.com/questions/51062/constructor-parameter-validation-in-...

What are the advantages of built-in immutability of F# over C#?

What are the advantages of built-in immutability of F# over C#? 1. I heard F# has native support for immutability but what about it that can not be replicated in C#? What do you get by an F# immutable...

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...

27 Jul at 18:36

Why are immutable objects thread-safe?

Why are immutable objects thread-safe? ``` class Unit { private readonly string name; private readonly double scale; public Unit(string name, double scale) { this.name = name; this.scale...

24 Sep at 22:36

Does using public readonly fields for immutable structs work?

Does using public readonly fields for immutable structs work? Is this a proper way to declare immutable structs? I can't think of why this would run into problems, but I just wanted to ask to make sur...

19 May at 18:45

Replace Multiple String Elements in C#

Replace Multiple String Elements in C# Is there a better way of doing this... I've extended the string class to keep it down to one job but is there a quicker way? ``` public static class StringExtens...

10 Jun at 15:34

In C#, why can't I modify the member of a value type instance in a foreach loop?

In C#, why can't I modify the member of a value type instance in a foreach loop? I know that value types should be immutable, but that's just a suggestion, not a rule, right? So why can't I do somethi...

5 Feb at 21:43

Are readonly structs supposed to be immutable when in an array?

Are readonly structs supposed to be immutable when in an array? (Note: This sample code requires C# 7.2 or later, and the [Nuget System.Memory](https://www.nuget.org/packages/System.Memory/) package.)...

7 Feb at 02:55

Immutable objects that reference each other?

Immutable objects that reference each other? Today I was trying to wrap my head around immutable objects that reference each other. I came to the conclusion that you can't possibly do that without usi...

20 Jul at 04:52

C# immutable int

C# immutable int In Java strings are immutable. If we have a string and make changes to it, we get new string referenced by the same variable: [It's been said](https://stackoverflow.com/questions/3981...

23 May at 12:9

Can we get access to the F# copy and update feature from c#?

Can we get access to the F# copy and update feature from c#? For example in F# we can define and to update it I can do That's brilliant and the fact that records automatically implement IStructuralEqu...

9 Aug at 17:4

Enums in Javascript with ES6

Enums in Javascript with ES6 I'm rebuilding an old Java project in Javascript, and realized that there's no good way to do enums in JS. The best I can come up with is: The `const` keeps `Colors` from ...

ImmutableSortedDictionary range enumeration by key

ImmutableSortedDictionary range enumeration by key I was reading about C#'s `ImmutableSortedDictionary` in `System.Collections.Immutable` and thinking about how to apply it in my program. I quite like...

Immutability and XML Serialization

Immutability and XML Serialization I have several classes that are immutable once their initial values are set. Eric Lippert calls this [write-once immutability](http://blogs.msdn.com/ericlippert/arch...

19 Aug at 22:27

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

Do not declare read only mutable reference types - why not? I have been reading [this question](https://stackoverflow.com/questions/2274412/immutable-readonly-reference-types-fxcop-violation-do-not-de...

23 May at 12:30

Java Immutable Collections

Java Immutable Collections From [Java 1.6 Collection Framework documentation](http://download.oracle.com/javase/6/docs/technotes/guides/collections/overview.html): > Collections that do not support an...

16 Mar at 06:37