这段代码中WareHouseCode的数据从哪获得 private void GetLocationXY() { var configList = string.IsNullOrEmpty(WareHouseCode) ? ExcelConfig.Instance.RouteConfigList.Where(d => !string.IsNullOrEmpty(d.WareHouseCode)) : ExcelConfig.Instance.RouteConfigList.Where(d => d.WareHouseCode == WareHouseCode); configList = configList.Where(d => d.X != 0 && d.Y != 0); if (configList.Count() == 0) { return; }
时间: 2024-04-07 14:32:32 浏览: 12
在这段代码中,WareHouseCode应该是一个属性或字段,用于存储当前仓库的编号。根据代码逻辑,如果WareHouseCode属性的值为空字符串,那么configList集合中的元素应该是ExcelConfig.Instance.RouteConfigList中所有WareHouseCode不为空的元素。
如果WareHouseCode属性的值不为空,那么configList集合中的元素应该是ExcelConfig.Instance.RouteConfigList中WareHouseCode等于WareHouseCode属性值的元素。
接下来,代码对configList进行了一些筛选,只保留那些X和Y坐标不为0的元素。最后,如果configList集合中没有元素,那么直接返回,否则继续执行后面的代码,对X和Y坐标进行一些处理。
相关问题
这段代码都用到了什么知识如何学习 if (tempMatchList != null && tempMatchList.Count > 0) { var tempMatch = tempMatchList .Where(d => string.IsNullOrEmpty(d.WarehouseCode) ? true : d.WarehouseCode == pmsTaskInfo.WareHouseCode) .Where(d => string.IsNullOrEmpty(d.LocationCode) ? true : d.LocationCode == pmsTaskInfo.LocationCode) .Where(d => string.IsNullOrEmpty(d.TargetWarehouseCode) ? true : d.TargetWarehouseCode == pmsTaskInfo.TargetWareHouseCode) .Where(d => string.IsNullOrEmpty(d.TargetLocationCode) ? true : d.TargetLocationCode == pmsTaskInfo.TargetLocationCode) .FirstOrDefault(); if (tempMatch != null) { data.TemplateName = tempMatch.TemplateName; data.AgvId = tempMatch.AgvId > 0 ? tempMatch.AgvId : data.AgvId; data.AgvType = !string.IsNullOrEmpty(tempMatch.AgvType) ? tempMatch.AgvType : data.AgvType; data.Priority = tempMatch.Priority > 0 ? tempMatch.Priority : data.Priority; CLog.Instance.TaskLog.WriteInfo($"{data.TaskId} {tempMatch.WarehouseCode} {tempMatch.LocationCode} => {tempMatch.TargetWarehouseCode} {tempMatch.TargetLocationCode} " + $"匹配到任务信息: {tempMatch.TemplateName} AgvId:{tempMatch.AgvId} AgvType:{tempMatch.AgvType} Priority:{tempMatch.Priority}"); } }
这段代码主要用到了C#编程语言和LINQ语言集成查询。
要学习这段代码,需要掌握以下知识:
1. C#编程语言:了解C#语言的基本语法、面向对象编程等内容。
2. LINQ语言集成查询:学习LINQ语言集成查询的基本概念、语法、查询运算符等内容。
3. List集合:了解List集合的基本概念、方法和属性等内容。
4. Lambda表达式:了解Lambda表达式的基本概念、语法和用法等内容。
5. 委托:了解委托的基本概念、定义和使用方法等内容。
需要注意的是,学习LINQ语言集成查询不仅需要理论知识,还需要实践经验。建议通过编写实际代码来加深对LINQ的理解和掌握。同时,需要了解List集合、Lambda表达式和委托等相关知识,才能更好地理解和使用LINQ语言集成查询。
private void LoginForm_Load(object sender, EventArgs e) { // 加载保存的账号密码 textBox1.Text = Properties.Settings.Default.username?.ToString(); textBox2.Text = Properties.Settings.Default.password?.ToString(); checkBox2.Checked = !string.IsNullOrEmpty(Properties.Settings.Default.username); }这段代码在winform中,说明为什么username和password会报错并说明如何修改
`Properties.Settings.Default.username`和`Properties.Settings.Default.password`默认值为null,如果直接将其值赋给文本框,就会引发空引用异常。因此,我们需要使用空值合并运算符`??`来判断这些属性是否为空,如果为空则将其值设置为一个默认值。
例如,我们可以将其默认值设置为空字符串,如下所示:
```csharp
private void LoginForm_Load(object sender, EventArgs e)
{
// 加载保存的账号密码
textBox1.Text = Properties.Settings.Default.username ?? "";
textBox2.Text = Properties.Settings.Default.password ?? "";
checkBox2.Checked = !string.IsNullOrEmpty(Properties.Settings.Default.username);
}
```
这样修改之后,如果`Properties.Settings.Default.username`和`Properties.Settings.Default.password`为空,程序会将文本框的值设置为空字符串,而不会引发空引用异常。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)