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=PropertyChanged1.ConcurrentDictionary
ConcurrentDictionary 并发字典,保证多线程情况下的安全性
Dictionary 非线程安全集合
using System.Collections.Concurrent;
class Program { static void Main(string[] args) { ConcurrentDictionary<string, Student> students = new ConcurrentDictionary<string, Student>(); ConcurrentDictionary<string, Teacher> teachers = new ConcurrentDictionary<string, Teacher>(); // 添加键值对 students.TryAdd("刘一凡", new Student {Grade=1 ,Sex=Sex.Male,Age = 10}); teachers.TryAdd("顾老师", new Teacher {TeachSubject="语文",Sex = Sex.Female,Age=45 }); ////查询顾老师的信息 if (teachers.TryGetValue("顾老师", out var teacher)) { Console.WriteLine($"顾老师教授科目为:{teacher.TeachSubject}"); Console.WriteLine($"顾老师年龄为:{teacher.Age}"); } if (students.TryGetValue("刘一凡", out var student)) { Console.WriteLine($"刘一凡所在年级为:{student.Grade}"); Console.WriteLine($"刘一凡性别为:{student.Sex}"); } } }
enum Sex { Male, Female } internal class People { private int age; /// <summary> /// 年龄 /// </summary> public int Age { get { return age; } set { age = value; } } private Sex sex; /// <summary> /// 性别 /// </summary> public Sex Sex { get { return sex; } set { sex = value; } } }
internal class Student:People { private int grade; /// <summary> /// 年级 /// </summary> public int Grade { get { return grade; } set { grade = value; } } } internal class Teacher : People { private string teachSubject; /// <summary> /// 教授科目 /// </summary> public string TeachSubject { get { return teachSubject; } set { teachSubject = value; } } }
2.ManualResetEvent
表示必须手动重置信号的线程同步事件。 无法继承此类。
public sealed class ManualResetEvent : System.Threading.EventWaitHandle
static ManualResetEvent mre = new ManualResetEvent(false); static void Main(string[] args) { Thread th = new Thread(new ThreadStart(()=> { Thread.Sleep(1000); Console.WriteLine("Async Time =" + DateTime.Now.ToString("hh:mm:ss fff")); Thread.Sleep(5000); mre.Set(); })); th.Start(); Console.WriteLine("Start Time =" + DateTime.Now.ToString("hh:mm:ss fff")); mre.Reset(); bool isback = mre.WaitOne(); Console.WriteLine($"IsBack = {isback}"); Console.WriteLine("End Time =" + DateTime.Now.ToString("hh:mm:ss fff")); Console.Read(); }
3.wpf“调用线程无法访问此对象,因为另一个线程拥有该对象。
this.Dispatcher.Invoke(new Action(delegate
{
}));
4.Windows Presentation Foundation (WPF) 项目中不支持 Application
重新添加引用:PresentationCore PresentationFramework WindowsBase
------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!