摘要: var date = new DateTime(1731, 11, 25); Console.WriteLine($"On {date:dddd, MMMM dd, yyyy} Leonhard Euler introduced the letter e to denote {Math.E:F5} 阅读全文
posted @ 2023-10-05 15:31 Tammytan 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 一.声明一个MyClass对象 public class MyClass { public int MyField; } 二.获取RequiredAttribute类型信息 MyClass instance = new MyClass(); FieldInfo field = instance.Ge 阅读全文
posted @ 2023-04-26 17:05 Tammytan 阅读(543) 评论(0) 推荐(0) 编辑
摘要: void M(object o1, object o2) { var t = (o1, o2); if (t is (int, string)) {} // test if o1 is an int and o2 is a string switch (o1) { case int: break; 阅读全文
posted @ 2023-04-13 16:28 Tammytan 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 如果标记了[NonSerialized]特性,会防止将该字段序列化。但是,该字段仍然可以用于foreach迭代,因为它仍然是枚举的有效成员。如果要防止特定枚举成员被foreach迭代,用[NonSerialized]特性是不起作用的。相反,可以创建一个自定义的Attribute继承自System.A 阅读全文
posted @ 2023-04-12 14:06 Tammytan 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 调用表达式 () 使用括号 () 调用()或调用委托。 以下示例演示如何在使用或不使用参数的情况下调用方法,以及调用委托: Action<int> display = s => Console.WriteLine(s); var numbers = new List<int>(); numbers. 阅读全文
posted @ 2023-04-07 10:29 Tammytan 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 实例一: JsonSerializerSettings jsonSettings = new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss.fff", }; Model model = new Model { Cre 阅读全文
posted @ 2023-04-03 17:30 Tammytan 阅读(955) 评论(0) 推荐(0) 编辑
摘要: 一.下面是一个示例代码,该代码使用iTextSharp将多个PDF文件合并为一个: public static void MergePDFs(string[] pdfPaths, string outputPath) { using (FileStream stream = new FileStre 阅读全文
posted @ 2023-04-03 11:09 Tammytan 阅读(435) 评论(0) 推荐(0) 编辑
摘要: 一维数组 使用 new 运算符创建一维数组,该运算符指定数组元素类型和元素数。下面的示例声明一个包含五个整数的数组: //数组初始化int[] array = new int[5]; int[] array1 = new int[] { 1, 3, 5, 7, 9 };string[] weekDa 阅读全文
posted @ 2023-03-31 11:11 Tammytan 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 委托是一种安全封装方法的类型,类似于 C 和 C++ 中的函数指针。与 C 函数指针不同,委托是面向对象的、类型安全的。委托的类型由委托的名称定义。下面的示例声明一个名为的委托,该委托可以封装将字符串作为参数并返回 void 的方法: public delegate void Del(string 阅读全文
posted @ 2023-03-30 13:45 Tammytan 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 1. 单一职责原则(Single Responsibility Principle)类T负责两个不同的职责:职责P1,职责P2。 using System; using System.Collections.Generic; using System.Linq; using System.Text; 阅读全文
posted @ 2023-02-22 13:50 Tammytan 阅读(18) 评论(0) 推荐(0) 编辑