[英]How to fix Dictionary setter issue
I have created a dictionary. 我已经创建了字典。 But during Build it gives me error: 但是在构建过程中,它给了我错误:
Change 'INotificationMessage.AlertMessageList ' to be read-only by removing the property setter 通过删除属性设置器,将“ INotificationMessage.AlertMessageList”更改为只读
public interface INotificationMessage
{
/// <summary>
/// Gets or sets the notification message list.
/// </summary>
/// <value>
/// The notification message list.
/// </value>
Dictionary<string, string> AlertMessageList { get; set; }
}
Can please ayone assist me to fix this issue. 可以请大家帮我解决此问题。
Generally you shouldn't have a public set for collections as this allows the list to be replaced. 通常,您不应该为集合设置公共集,因为这样可以替换列表。 Just use: 只需使用:
Dictionary<string, string> AlertMessageList { get; }
To fix it you can add method for set that collection or use: 要修复它,您可以添加用于设置该集合或使用的方法:
Dictionary<string, string> AlertMessageList { get; private set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.