2016-11-25 53 views
1

我已經創建了一本字典。但是生成過程中它給我的錯誤:如何解決字典設置問題

Change 'INotificationMessage.AlertMessageList ' to be read-only by removing the property setter

public interface INotificationMessage 
    { 
     /// <summary> 
     /// Gets or sets the notification message list. 
     /// </summary> 
     /// <value> 
     /// The notification message list. 
     /// </value> 
     Dictionary<string, string> AlertMessageList { get; set; } 
    } 

可以請ayone幫助我解決這個問題。

回答

2

通常,您不應該爲集合設置公共集合,因爲這允許替換列表。只需使用:

Dictionary<string, string> AlertMessageList { get; } 

要解決它,你可以爲組收集或使用添加方法:

Dictionary<string, string> AlertMessageList { get; private set; } 

Collection properties should be read only

+0

如果您需要設置強制implemation用於獲取列表,只需在接口中添加一個方法void SetAlertMessageList(Dictionary dict) Dictionary SetAlertMessageList() – user1519979

+0

@Raj Hello。如果有幫助請接受答案。如果不是,那麼描述是什麼問題。在此先感謝您 – Marusyk

+0

@MegaTron能否請您建議如何在界面中添加一個方法來設置屬性。 – Raj