C# - 如何将Dictionary或HashSet作为只读集合返回?

Jay*_*Jay 6 c# data-structures

可能重复:
.NET中是否有只读的通用字典?

嗨,大家好,

我意识到可以将列表作为只读集合返回:

var list = new List<string>();
return list.AsReadOnly();
Run Code Online (Sandbox Code Playgroud)

我想为像Dictionary或HashSet这样的数据结构编写类似的代码,但我没有找到实现这一目标的方法.有没有办法将Dictionary或HashSet作为只读集合返回?

谢谢.