随笔分类 -  .NET6

摘要:提问 集合类型如何使用 回答 长度不变使用数组; 集合涉及增删使用List; 作为参数使用IEnumable; 作为返回值参考第一第二条规则; 阅读全文
posted @ 2023-10-07 09:15 东百牧码人 阅读(6) 评论(0) 推荐(0)
摘要:提问 数组能改变大小吗 回答 能 using System; public class SamplesArray { public static void Main() { // Create and initialize a new string array. String[] myArr = { 阅读全文
posted @ 2023-09-28 16:07 东百牧码人 阅读(15) 评论(0) 推荐(0)
摘要:提问 如何获取枚举名称 回答 using System; public class GetNameTest { enum Colors { Red, Green, Blue, Yellow }; enum Styles { Plaid, Striped, Tartan, Corduroy }; pu 阅读全文
posted @ 2023-09-28 16:04 东百牧码人 阅读(41) 评论(0) 推荐(0)
摘要:提问 如何优雅地类型转换和非空判断 回答 使用模式匹配 😥 BAD Bytes2ValueAttribute attr = (Bytes2ValueAttribute) Attribute.GetCustomAttribute(p, typeof(Bytes2ValueAttribute)); i 阅读全文
posted @ 2023-09-28 09:28 东百牧码人 阅读(17) 评论(0) 推荐(0)
摘要:## 提问 C#如何生成密钥 ## 回答 ``` Aes aes = Aes.Create(); SecurityKey = Convert.ToBase64String(aes.Key); ``` ## 参考 https://learn.microsoft.com/zh-cn/dotnet/sta 阅读全文
posted @ 2023-06-07 16:56 东百牧码人 阅读(279) 评论(0) 推荐(0)
摘要:提问 C# Channel有哪些技巧 回答 判断管道中是否还有任务 return _channel.Reader.Count > 0; 结合Channel.CreateUnbounded (无边界管道)可实现整体任务缓存,避免重复写入 慎用ChannelWriter.Complete 这会造成管道关 阅读全文
posted @ 2023-04-13 09:56 东百牧码人 阅读(112) 评论(0) 推荐(0)
摘要:提问 线程中的终极异常处理处理 回答 为了异常阻塞主线程是不值得的 使用事件通知方式,这样不会阻塞主线程 捕捉AggregateException 阅读全文
posted @ 2023-04-11 08:54 东百牧码人 阅读(28) 评论(0) 推荐(0)
摘要:提问 如何写列表example注释 回答 使用[] 示例 /// <summary> /// 集合 /// </summary> /// <example>["asdfasdfeadfadf"]</example> public List<string>? Orders{ get; set; } 阅读全文
posted @ 2023-04-10 13:26 东百牧码人 阅读(19) 评论(0) 推荐(0)
摘要:提问 如何使用PLINQ 回答 在集合上应用AsParallel(); 假如顺序很重要则增加AsOrdered() 参考 阅读全文
posted @ 2023-04-07 08:45 东百牧码人 阅读(13) 评论(0) 推荐(0)
摘要:提问 WebApi接口如何用户名非数字参数验证 回答 [RegularExpression(pattern: @"^\D*$", ErrorMessage = "numeric user names not supported")][FromHeader(Name = "user_name")] s 阅读全文
posted @ 2023-04-06 11:27 东百牧码人 阅读(16) 评论(0) 推荐(0)
摘要:提问 多线程任务怎么选 Thread,ThreadPoll,Task 回答 Task 原因 Thread:创建销毁代价昂贵 ThreadPoll:管理线程资源 Task 基于线程池 阅读全文
posted @ 2023-04-04 09:57 东百牧码人 阅读(56) 评论(0) 推荐(0)
摘要:提问 如何让开发的命令行程序 回答 使用System.CommandLine脚手架让你的程序支持多种命令 参考 https://learn.microsoft.com/en-us/dotnet/standard/commandline/ 阅读全文
posted @ 2023-03-24 14:57 东百牧码人 阅读(9) 评论(0) 推荐(0)
摘要:提问 EF Core支持多线程并发吗 回答 不支持 报错 A second operation was started on this context instance before a previous operation completed. This is usually caused by 阅读全文
posted @ 2023-03-24 14:43 东百牧码人 阅读(109) 评论(0) 推荐(0)
摘要:提问 如何Linq左连接 回答 注意 into 推荐返回匿名类型 var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpt 阅读全文
posted @ 2023-03-23 14:28 东百牧码人 阅读(24) 评论(0) 推荐(0)
摘要:提问 C#如何进行并行任务 回答 最大并行书为系统CPU数 po.MaxDegreeOfParallelism = Environment.ProcessorCount; var po = new ParallelOptions(); po.MaxDegreeOfParallelism = Envi 阅读全文
posted @ 2023-03-22 08:56 东百牧码人 阅读(43) 评论(0) 推荐(0)
摘要:提问 如何buid自动升级版本 原因 在离线部署中为了构建版本可跟踪,只使用主版本、次版本、修订版是不够的,必须跟踪到每一次build; 解答 csproj文件增加 <PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> 阅读全文
posted @ 2023-03-20 13:17 东百牧码人 阅读(22) 评论(0) 推荐(0)
摘要:提问 应该为泛型提供约束吗 回答 应该 理由 ”约束“这个词可能会引起歧义,有些人可能认为对泛型参数设定约束是限制参数的使用,实际情况正好相反。没有约束的泛型参数作用很有限,倒是”约束“让泛型参数具有了更多的行为和属性。 public class Salary { /// <summary> /// 阅读全文
posted @ 2023-03-20 10:38 东百牧码人 阅读(14) 评论(0) 推荐(0)
摘要:提问 WebApi 单文件发布Serilog 失效怎么解决 回答 配置文件Appsetting.json增加Using块 "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], 示例 { "Serilog": { "Using": [ 阅读全文
posted @ 2023-03-17 10:45 东百牧码人 阅读(90) 评论(0) 推荐(1)
摘要:提问 如何优雅的时使用TryParse 回答 YES var d = double.TryParse("3.1415", out var value) ? value : 0, NO var value = 0d; var ok = double.TryParse("3.1415", out val 阅读全文
posted @ 2023-03-16 10:15 东百牧码人 阅读(23) 评论(0) 推荐(0)
摘要:提问 如何Jenkins发布NetCore程序 回答 cd BluePig taskkill /F /im BluePig.exe nssm stop BluePig nssm remove BluePig confirm del /s /f /q publish dotnet restore do 阅读全文
posted @ 2023-02-14 09:39 东百牧码人 阅读(23) 评论(0) 推荐(0)