在这个 c# 代码中,我需要将 userName 值从 string 转换为 int 类型。有谁知道请帮帮我。我收到错误作为编译错误“无法将 lambda 表达式转换为类型'int',因为它不是委托类型”,就像这样。
ShoppingCartPartRecord cartRecord = null;
try {
cartRecord = _shoppingCartRepository.Get(r => r.Username == userName);
}
catch (InvalidOperationException ex) {
if (ex.Message == "Sequence contains more than one element") {
var badCarts = _shoppingCartRepository.Table.Where(x => x.Username == userName);
foreach (var shoppingCartPartRecord in badCarts) {
_shoppingCartRepository.Delete(shoppingCartPartRecord);
}
}
}
先感谢您。