c# - 如何从异常处理中排除当前选定的项目
问题描述
我对 C# 比较陌生,目前正在处理一个我想从异常中排除已编辑项目的项目。但是,在这种情况下,用户可以编辑包括约会在内的约会;不能有重叠的约会。当我运行我的程序并编辑约会时,例外是检查不应该编辑的约会。有人可以建议我如何做到这一点吗?
foreach (var appt in AppointmentScreen.ListOfAppts)
{
if (selectedStart <= appt.Start && selectedEnd > appt.Start && (!(SelectApptID >= 0)) || SelectApptID >= 0)
{
overlaping = true;
}
if (appt.Start <= selectedStart && appt.End > selectedStart && (!(SelectApptID >= 0)) || SelectApptID >= 0)
{
overlaping = true;
}
}
如果需要更多信息,请告诉我。我将全天定期检查。
感谢您提前提供的所有帮助
解决方案
正在编辑的约会是否有一个唯一的 ID,您可以使用它进行检查?
如果不是,如何将 Guid 属性添加到约会对象并使用简单的条件跳过(如果它是当前的)?就像是:
foreach (var appt in AppointmentScreen.ListOfAppts)
{
if (appt.Id == CurrentAppt.Id) continue; //this condition skips the appointment being edited
if (selectedStart <= appt.Start && selectedEnd > appt.Start && (!(SelectApptID >= 0)) || SelectApptID >= 0)
{
overlaping = true;
}
if (appt.Start <= selectedStart && appt.End > selectedStart && ((SelectApptID >= 0)) || SelectApptID >= 0)
{
overlaping = true;
}
}
在您的约会课程中:
public class Appointment
{
public Guid Id { get; set; }
.
.
.
}
推荐阅读
- javascript - 如何在javascript html中为父/子添加节点
- spring - Spring OAuth2 - 如何一起使用授权类型`password`和`client_credentials`但过期时间不同
- python - 有没有办法使用 python 向文件添加属性/元数据?
- javascript - 有向无环图的平面计算
- r - 将预测结果保存在 R 中的 csv 文件中
- reactjs - PureComponent 中的受控输入不会在更改时呈现
- javascript - 调用 Firestore 集合时如何使用 orderBy?
- json - 如何使用 Gatling 从 JSON 文件中提取字段
- docker - docker swarm init --advertise-addr 如何工作?
- php - 在 PHP 中将表单数据插入 MySQL