当前位置: 首页 > news >正文

模拟一个集合 里面是设备号和每日的日期

问题: 需要模拟一个集合 里面是设备号和每日的日期
代码如下:

        static void Main(string[] args){string equipmentCodePar = "";DateTime time = DateTime.Now; // 获取当前时间DateTime startDate = time.AddDays(1 - time.Day);//获取当前月第一天DateTime endDate = startDate.AddMonths(1).AddDays(-1); // 例:2023年1月31日List<string> Sclist = new List<string>() { "S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09" };if (!string.IsNullOrEmpty(equipmentCodePar)) Sclist = Sclist.Where(p => p.Contains(equipmentCodePar)).ToList();//var equipmentDateCombinations =from equipmentCode in Sclist.Select(info => info)from date in Enumerable.Range(0, (endDate - startDate).Days + 1).Select(offset => startDate.AddDays(offset)) select new { EquipmentCode = equipmentCode, Date = date.Date };Console.WriteLine("day"+(endDate - startDate).Days);foreach (var i in Enumerable.Range(0, (endDate - startDate).Days + 1)){Console.WriteLine(i);}Console.WriteLine();}

主要使用了

Enumerable.Range(0, (endDate - startDate).Days + 1).Select(offset => startDate.AddDays(offset))

在微软的官方文档中 Enumerable.Range

// Generate a sequence of integers from 1 to 10
// and then select their squares.
IEnumerable<int> squares = Enumerable.Range(1, 10).Select(x => x * x);foreach (int num in squares)
{Console.WriteLine(num);
}/*This code produces the following output:149162536496481100
*/
http://www.lryc.cn/news/254633.html

相关文章:

  • antdesign前端一直加载不出来
  • 排序算法介绍(一)插入排序
  • 2023新优化应用:RIME-CNN-LSTM-Attention超前24步多变量回归预测算法
  • RNN:文本生成
  • Rust UI开发(五):iced中如何进行页面布局(pick_list的使用)?(串口调试助手)
  • Linux学习笔记2
  • 数据结构算法-插入排序算法
  • 安装Kuboard管理K8S集群
  • 网络安全行业大模型调研总结
  • Linux AMH服务器管理面板本地安装与远程访问
  • Sharding-Jdbc(3):Sharding-Jdbc分表
  • zookeeper集群 +kafka集群
  • 2022年全国大学生数据分析大赛医药电商销售数据分析求解全过程论文及程序
  • Python版本与opencv版本的对应关系
  • 【开源视频联动物联网平台】LiteFlow
  • 家用智能门锁——智能指纹锁方案
  • Qt6 QRibbon 一键美化Qt界面
  • JAVA IO:NIO
  • Python 在控制台打印带颜色的信息
  • SQL Server 数据库,创建触发器避免数据被更改
  • C语言实现植物大战僵尸(完整版)
  • 基于YOLOv8深度学习的火焰烟雾检测系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、深度学习实战
  • 【C++】手撕string思路梳理
  • 【数据结构和算法】确定两个字符串是否接近
  • [足式机器人]Part2 Dr. CAN学习笔记-Ch0-1矩阵的导数运算
  • 如何让软文更具画面感,媒介盒子分享
  • Hadoop学习笔记(HDP)-Part.19 安装Kafka
  • Arrays类练习 - Java
  • Java多线程:代码不只是在‘Hello World‘
  • 使用PCSS实现的实时阴影效果