C# 非泛型集合的简单迭代
1.C# 中数字常见操作及其取值范围2.C# 泛型列表类型管理数据集合3.C# 通过Queue类来实现队列的先进先出
4.C# 非泛型集合的简单迭代
5.C# 语言集成查询LINQ6.委托简单实现7..net 和.net framework区别8.C#-随笔杂记9.wpf-TextBlock文本内容自动换行10.C# 非引用类型初始化为空11.C#------------await12.C#------新特性之??、?、??= 使用13.C#------LINQ查询(一)14.C#——LINQ to XML(创建 XML 树)15.C#——LINQ to XML(内容快速查找)16.C#——LINQ to XML(使用 Descendants 方法查找单个子代)17.C#——fixed用法18.C#——匿名类型19.C#——属性init访问器方法20.C#——自动实现的属性21.C#——对象初始值设定项22.Assembly.CreateInstance 方法和Activator.CreateInstance 方法(C#)23.DragDrop.DoDragDrop(DependencyObject, Object, DragDropEffects) 方法——控件拖动方法24.通讯过程中16进制字符和byte[]/十进制和16进制转换(一)25.C# Modbus Tcp 实现(二)26.C# Modbus Tcp实现(一)27.C# 进制变换过程中左侧填充0实现28.DLR(动态语言运行时)(一)29.wpf textbox中UpdateSourceTrigger=PropertyChangedIEnumerator接口:支持对非泛型集合的简单迭代,使得foreach可以遍寻集合
using System; using System.Collections;
public class Family { private string husban = null; public string Husban { get { return husban; } set { husban = value; } } private string wife = null; public string Wife { get { return wife; } set { this.wife = value; } } private string son = null; public string Son { get { return this.son; } set { this.son = value; } } private string daughter = null; public string Daughter { get { return this.daughter; } set { this.daughter = value; } } public Family(string husban, string wife, string daughter, string son) { this.husban = husban; this.wife = wife; this.daughter = daughter; this.son = son; } } public class Families : IEnumerable { Family[] families; public Families(Family[] familyList) { this.families = new Family[familyList.Length]; for (int i = 0; i < familyList.Length; i++) this.families[i] = familyList[i]; } IEnumerator IEnumerable.GetEnumerator() { return (IEnumerator)this.GetEnumerator(); } FamilyEnumerator GetEnumerator() { return new FamilyEnumerator(this.families); } } public class FamilyEnumerator : IEnumerator { public Family[] families; int index = -1; public FamilyEnumerator(Family[] familyList) { this.families = familyList; } /// <summary> /// 将枚举数设置为其初始位置,该位置位于集合中第一个元素之前 /// </summary> public void Reset() { index = -1; } /// <summary> /// 获取集合中位于枚举数当前位置的元素 /// </summary> public Family Current { get { try { return this.families[index]; } catch (IndexOutOfRangeException e) { throw new InvalidOperationException(); } } } /// <summary> /// 将枚举数推进到集合的下一个元素 /// </summary> /// <returns></returns> public bool MoveNext() { index++; return index < this.families.Length; } object IEnumerator.Current { get { return Current; } } }
static void Main(string[] args) { Family[] familyList = new Family[] { new Family("echo","zp","cc","ef"), new Family("zhubaba","zhumama","peiqi","qiaozhi"), }; Families families = new Families(familyList); foreach (Family fam in families) { Console.WriteLine($"{fam.Husban} {fam.Wife} {fam.Son} {fam.Daughter}"); } }
------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!