0

I want to use ValueTuple or Tuple in Dictionary together and to be able to change content/variable. But it says

Cannot modify the return value of because it is not a variable

Actually, I want to be able to store data in dictionary without creating new class/struct and can change value content by a name(date, IsOk) like below.

This would make really easy to keeping date in a structured way without new types...

Error message

livan3li
  • 119
  • 2
  • 8
  • 1
    maybe consider using `with` though it will create a new instance and doesn’t make the existing instance mutable https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression – Rand Random Aug 20 '23 at 18:42
  • ValueTuple is a value type. You could use `Tuple`which is a reference tpye – Klaus Gütter Aug 20 '23 at 18:42
  • 3
    New types/classes aren't bad. They have real name that tell what they are really doing and are easy to write. You are now trying something that a.) won't work as you learned and b.) will get you you into trouble if you somehow get it to work. ValueTuples are struct that means they get copied in most occasions when used. Mutable structs get you in trouble simply don't do it. They is absolutely no need for that here. – Ralf Aug 20 '23 at 18:43
  • @KlausGütter - though even with tuple there is no setter, and it’s still immutable see eg. https://stackoverflow.com/questions/19725158/why-a-tuple-or-a-keyvalueitem-dont-have-a-setter – Rand Random Aug 20 '23 at 18:44
  • Related: [Modify Struct variable in a Dictionary](https://stackoverflow.com/questions/6255305/modify-struct-variable-in-a-dictionary). – Theodor Zoulias Aug 20 '23 at 19:01
  • 2
    `dict["bun"] = (dict["bun"].date, true);` – Dmitry Bychenko Aug 20 '23 at 19:25
  • @DmitryBychenko thank you very much budy, that's the thing i wanted. You can post as answer i'd mark as accepted But question has been closed. I looked at that post but it is not quite similar. I didn't even understand it. – livan3li Aug 21 '23 at 05:59

0 Answers0