About 173,000 results
Open links in new tab
  1. In C# , Are Value types mutable or immutable - Stack Overflow

    Aug 17, 2011 · Mutable value types are a bad idea, and should be avoided. For example, what does this code do: SomeType t = new SomeType(); t.X = 5; SomeType u = t; t.X = 10; Console.WriteLine(u.X); It depends. If SomeType is a value type, it prints 5, which is a pretty confusing result. See this question for more info on why you should avoid mutable value types.

  2. What is the difference between a mutable and immutable string in …

    Nov 25, 2010 · String is the standard C# / .Net immutable string type; StringBuilder is the standard C# / .Net mutable string type; To "effect a change" on a string represented as a C# String, you actually create a new String object. The original String is …

  3. c# - Examples of Immutable Types in .Net - Stack Overflow

    Jul 30, 2015 · All anonymous types created by the compiler (new { ... } in C#, New With { ... } in VB.NET) (Wrong for two reasons: These types are not in the FCL, and apparently VB.NET types are mutable.) All enumeration types (enum, Enum) All delegate types. (see this answer. While it might seem that delegates are mutable (since you can do things like obj ...

  4. c# 4.0 - What are mutable Classes. How can we create a mutable …

    Oct 3, 2016 · C# also lacks syntactic support for Record types, which unfortunately were pulled from C# 7, so we'll have to wait another year for that (Update: As of mid-2018, C# 8.0 is expected to have Record types, but C# 8.0 probably won't be finally released until into 2020 given its very long list of new features).

  5. c# - Why are mutable structs “evil”? - Stack Overflow

    Jan 14, 2009 · Just pass them with ref, around and there is nothing that can go wrong. The only problem I find are the restrictions of the C# compiler and that, in some cases, I am unable to force the stupid thing to use a reference to the struct, instead of a Copy(like when a struct is part of a C# class). So, mutable structs are not evil, C# has made them ...

  6. Why are C# number types immutable? - Stack Overflow

    Oct 20, 2010 · I think you might be mistaken about how value types work. This isn't some costly operation like you may be imagining; it's simply the overwriting of data (as opposed to, e.g., dynamic allocation of new memory). Secondly: here's a very simple example of why numbers are immutable: 5.Increase(1); Console.WriteLine(5); // What should happen here?

  7. c# - How to create mutable .NET strings? - Stack Overflow

    Oct 21, 2018 · System.Text.StringBuilder Class is a mutable string. You can use the indexer to change the char in pos (one char only), and use the Insert, Replace, Append, and AppendLine to make changes to the StringBuilder itself in the fastest way possible.

  8. Immutable type and property in C# - Stack Overflow

    May 13, 2012 · An immutable Type is a type where all (externally visible) properties and fields are immutable - for example the "Record" Type originally scheduled for C#7 (hopefully now 8) would have been an immutable type. Other examples of Immutable Types are Tuples, and all anonymous classes.

  9. Why only string is immutable & not other data types

    Sep 1, 2014 · See "In C#, why is String a reference type that behaves like a value type?", "Is string a value type or a reference type?" and "Why is string a reference type?" for the problems the C# deign team was trying to solve. (Most programming languages find it hard to fit strings into the type system.)

  10. .net - Why are C# structs immutable? - Stack Overflow

    Oct 10, 2012 · In a mutable structure you typically end up making copies of data to re-use it because you don't want changes to one logical object affecting another. This can save lots of time and memory. Reasons to make structs immutable. There are lots of reasons to make structs immutable. Here's just one. Structs are copied by value, not by reference.

Refresh