Asp.net 集合上的代码分析警告

Asp.net 集合上的代码分析警告,asp.net,Asp.net,我目前正在使用以下命令来存储会话中的对象集合。但是,我收到一条代码分析警告,“集合属性应为只读” 公共类银行详细信息 { //私有构造函数 公共字符串BankKey{get;set;} 公共字符串BankAccountHolder{get;set;} 公共字符串TypeOfAccount{get;set;} 公共字符串BankAccountNumber{get;set;} 公共字符串BankName{get;set;} 公共字符串余额{get;set;} 公共字符串分支{get;set;} 公共

我目前正在使用以下命令来存储会话中的对象集合。但是,我收到一条代码分析警告,“集合属性应为只读”

公共类银行详细信息
{
//私有构造函数
公共字符串BankKey{get;set;}
公共字符串BankAccountHolder{get;set;}
公共字符串TypeOfAccount{get;set;}
公共字符串BankAccountNumber{get;set;}
公共字符串BankName{get;set;}
公共字符串余额{get;set;}
公共字符串分支{get;set;}
公共字符串标志{get;set;}
公共字符串NewContactType{get;set;}
公共字符串OwnerPlatFormID{get;set;}
公共静态列表现有银行详细信息
{
收到
{
将HttpContext.Current.Session[“ExistingBankDetails”]作为列表返回??新建
List();
}
设置
{ 
HttpContext.Current.Session[“ExistingBankDetails”]=值;
}
}
公共静态列表详细信息
{
收到
{
将HttpContext.Current.Session[“NewBankDetails”]作为列表返回??新建
List();
}
设置
{ 
HttpContext.Current.Session[“NewBankDetails”]=值;
}
}
公共作废SetNewBankDetails(列表详细信息)
{
详情=新银行详情;
}
public void GetExistingBankDetails(列出existingDetails)
{
existingDetails=ExistingBankDetails;
}
}
}

有没有关于重写此代码以通过代码分析警告的提示?

更改此选项:

public static List<BankDetails> ExistingBankDetails
公共静态列表现有银行详细信息
对此,请改为:

public static IEnumerable<BankDetails> ExistingBankDetails
公共静态IEnumerable现有银行详细信息

以及所有其他声明

允许对集合进行修改,而不是替换集合中的全部内容,这难道不是更正常吗?(同样奇怪的是,您的getter没有填写会话值,而是允许在set之前进行多次调用以创建多个集合)
public static IEnumerable<BankDetails> ExistingBankDetails