Page 1 of 1

Wie kann ich eine neue Instanz von Immutabledictionary erstellen?

Posted: 05 Feb 2025, 12:05
by Guest
Ich möchte so etwas schreiben: < /p>

Code: Select all

var d = new ImmutableDictionary { { "a", 1 }, { "b", 2 } };
< /code>

(mithilfe von ImmutableDictionary < /code> von System.collections.immable). Es scheint eine einfache Verwendung zu sein, da ich alle Werte im Voraus deklariere - keine Mutation dort. Dies gibt mir jedoch einen Fehler: < /p>


Der Typ 'System.Collections.Immutable.ImmutableDictionary
'hat keine Konstruktoren definiert


Wie soll ich ein neues unveränderliches Wörterbuch mit statischer Inhalt erstellen?