HashSetnumbers = new HashSet (); numbers.Add(10); numbers.Add(20); numbers.Add(30);
HashSetIn this example, a HashSet of strings named 'names' is created using object initializer syntax. The HashSet is initialized with four elements, "John", "Mary", "Peter", and "Rose". The Add method is used to add an additional element, "Rose", to the HashSet. The HashSet Add method is part of the C# language and is not a separate package or library.names = new HashSet { "John", "Mary", "Peter" }; names.Add("Rose");