How to properly use IReadOnlyDictionary?

时光怂恿深爱的人放手 提交于 2019-12-04 03:49:19
CodeCaster

.NET 4.5 introduced the ReadOnlyDictionary type that you could use. It has a constructor that accepts an existing dictionary.

When targeting lower framework versions, use the wrapper as explained in Is there a read-only generic dictionary available in .NET? and Does C# have a way of giving me an immutable Dictionary?.

Please note that when using the latter class, the collection initializer syntax won't work; that gets compiled to Add() calls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!