ResourceDictionary resources = new ResourceDictionary(); resources.Add("key1", "value1"); resources.Add("key2", "value2"); if (resources.Contains("key1")) { Console.WriteLine("ResourceDictionary contains key1"); } else { Console.WriteLine("ResourceDictionary does not contain key1"); }
This is an example of a ResourceDictionary defined in XAML. It contains a single resource - a color value with the key "myColor". We can use the Contains method in C# code to check if this key is present in the ResourceDictionary. Package/Library: This method is part of the .NET Framework and is included in the System.Windows namespace.#FF0000