if (addList1.Count != addList2.Count !=addList3.Count !=addList4.Count != addList5.Count)多个List相加如何判断list中数量都相等
时间: 2024-03-16 07:46:32 浏览: 18
要判断多个List中的数量是否相等,可以通过如下方式实现:
```
if (addList1.Count == addList2.Count
&& addList2.Count == addList3.Count
&& addList3.Count == addList4.Count
&& addList4.Count == addList5.Count)
{
// 执行相应的操作
}
else
{
// 执行数量不相等时的操作
}
```
这段代码会先判断addList1、addList2、addList3、addList4、addList5中的数量是否相等,如果相等则执行相应的操作,否则执行数量不相等时的操作。
相关问题
<!-- 主体区域 --> <section id="todoapp"> <!-- 输入框 --> <header class="header"> <h1><a href="table.html">小小记事本</a></h1> <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务" class="new-todo"></input> </header> <!-- 列表区域 --> <section class="main"> <ul class="todo-list"> <li class="todo" v-for="(item,index) in list"> <div class="view"> <span class="index">{{ index+1 }}.</span> <label>{{ item }}</label> <button class="destroy" @click="remove(index)"></button> </div> </li> </ul> </section> <!-- 统计和清空 --> <footer class="footer" v-show="list.length!==0"> <span class="todo-count" v-if="list.length!==0"> <strong>{{ list.length }}</strong> items left </span> <button v-show="list.length!==0" class="clear-completed" @click="clear"> Clear </button> <div id="todoapp"> <input type="text" v-model="inputValue" /> <button @click="add">添加</button> <ul> <li v-for="(item, index) in todoList" :key="index"> {{ item }} <button @click="remove(index)">删除</button> </li> </ul> </div> </footer> </section>实现记事本的增,添,查改
这段代码已经实现了记事本的添加和删除功能,但是没有提供查看和修改功能。如果需要实现查看和修改功能,可以考虑在每个任务项上添加一个编辑按钮,点击编辑按钮后将任务项的内容显示在输入框中,用户可以修改后保存。以下是修改后的代码:
```
<section id="todoapp">
<header class="header">
<h1><a href="table.html">小小记事本</a></h1>
<input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务" class="new-todo"></input>
</header>
<section class="main">
<ul class="todo-list">
<li class="todo" v-for="(item,index) in list">
<div class="view">
<span class="index">{{ index+1 }}.</span>
<label v-if="!item.editing">{{ item.content }}</label>
<input v-else v-model="item.content" @keyup.enter="save(index)" @blur="save(index)" class="edit">
<button class="edit-button" @click="edit(index)" v-if="!item.editing">编辑</button>
<button class="save-button" @click="save(index)" v-if="item.editing">保存</button>
<button class="destroy" @click="remove(index)"></button>
</div>
</li>
</ul>
</section>
<footer class="footer" v-show="list.length!==0">
<span class="todo-count" v-if="list.length!==0">
<strong>{{ list.length }}</strong> items left
</span>
<button v-show="list.length!==0" class="clear-completed" @click="clear"> Clear </button>
</footer>
</section>
```
在每个任务项上添加了一个编辑按钮和一个保存按钮,初始状态下只显示编辑按钮,当用户点击编辑按钮后,任务项的内容会变成一个输入框,同时编辑按钮隐藏,保存按钮显示。当用户修改内容后,可以按回车键或者点击保存按钮保存修改后的任务项内容。同时,也可以在输入框外点击,使输入框消失并保存修改后的内容。
List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" || i.分类 == "应用气象观测站(便捷)").Select(it => it.台站号).ToList(); loginfo.Info($"获取{dt.ToString("yyyy-MM-dd HH:00")}区域气象站天元信息"); re = GetObservData(token, RegionalStationConfig, dt); List<string> NotChectkstationinfo = new List<string>(); //新增 re.rows = re.rows.Where(it => !NotChectkstationinfo.Contains(it.station_code)).ToArray(); re.total = re.rows.Count(); if (re.total != 0) { foreach (var item in re.rows) { Ty_Monitor monitor = new Ty_Monitor(); monitor.observtime = dt; monitor.stationumber = item.station_code; monitor.region = item.town_name; monitor.type = ObservType.区域站.ToString(); int hour = dt.Hour; int yushu = hour % 8; int group = hour / 8 + 1; string type = string.Empty; switch (group) { case 1: type = item.group1.Substring(yushu * 2, 2); break; case 2: type = item.group2.Substring(yushu * 2, 2); break; case 3: type = item.group3.Substring(yushu * 2, 2); break; } monitor.errortype = int.Parse(type); Monitors.Add(monitor); } }依旧会把应用气象站(便捷)视为异常站点是为什么
根据代码,可能是因为在获取数据之前,已经将应用气象站(便捷)的台站号添加到了NotCheckstationinfo列表中,但在筛选数据时,使用的是名为NotChectkstationinfo的空列表,所以筛选时并没有排除应用气象站(便捷)的台站数据。
解决方法是,将列表名统一改为NotCheckstationinfo,并且在获取数据之前,先清空该列表,以防之前的数据对结果造成影响。代码修改如下:
```
List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" || i.分类 == "应用气象观测站(便捷)").Select(it => it.台站号).ToList();
loginfo.Info($"获取{dt.ToString("yyyy-MM-dd HH:00")}区域气象站天元信息");
re = GetObservData(token, RegionalStationConfig, dt);
NotCheckstationinfo.Clear(); //清空列表
re.rows = re.rows.Where(it => !NotCheckstationinfo.Contains(it.station_code)).ToArray();
re.total = re.rows.Count();
if (re.total != 0)
{
foreach (var item in re.rows)
{
Ty_Monitor monitor = new Ty_Monitor();
monitor.observtime = dt;
monitor.stationumber = item.station_code;
monitor.region = item.town_name;
monitor.type = ObservType.区域站.ToString();
int hour = dt.Hour;
int yushu = hour % 8;
int group = hour / 8 + 1;
string type = string.Empty;
switch (group)
{
case 1: type = item.group1.Substring(yushu * 2, 2); break;
case 2: type = item.group2.Substring(yushu * 2, 2); break;
case 3: type = item.group3.Substring(yushu * 2, 2); break;
}
monitor.errortype = int.Parse(type);
Monitors.Add(monitor);
}
}
```