以前在做数据库插入或者修改时 只能返回操作成功或者失败
如果要同时返回失败和失败异常记录 则只能返回一个model类 或者把两个参数用连接符拼起来 然后到bll层再去分隔
今天看到 KeyValuePair<bool, string> 很适合上面说的那种情况
![ContractedBlock.gif](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
KeyValuePair
<
bool
,
string
>
loginResult;
if (result)
loginResult = new KeyValuePair < bool , string > ( true , " 成功 " );
else
loginResult = new KeyValuePair < bool , string > ( false , " 失败 " );
if (loginResult .Key)
{
Response.Write(loginResult.Value);
}
if (result)
loginResult = new KeyValuePair < bool , string > ( true , " 成功 " );
else
loginResult = new KeyValuePair < bool , string > ( false , " 失败 " );
if (loginResult .Key)
{
Response.Write(loginResult.Value);
}