简体   繁体   中英

How to set a HashSet<string> as a Value in Dictionary?

I have an array of strings called "subjects". I'm trying to fill my dictionary and using some class as key and HashSet "string" as Value, but can't make it properly and receive an error "cannot convert string[] to System.Collections.Generic.HashSet"string"". So what i need to put in my dictionary to make it work?

Dictionary<Student, HashSet<string>> studentSubjectDict = new Dictionary<Student, HashSet<string>>();

studentSubjectDict.Add(Student11, subjects);

As @Jeron Mostert said, new HashSet<string>(subjects) or subjects.ToHashSet() solve this problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM