随笔分类 -  C#

摘要:1. int 转换成 enum public enum Suit { Spades, Hearts, Clubs, Diamonds } Suit spades = (Suit)0; Suit hearts = Enum.Parse(typeof(Suit), "1"); Suit tryClubs 阅读全文
posted @ 2021-03-03 20:19 鑫茂 阅读(152) 评论(0) 推荐(0)
摘要:使用一:可用于捕获报错时。 using System.Diagnostics; ... StackTrace st = new StackTrace(true); string stackIndent = ""; for (int i = 0; i < st.FrameCount; i++) { S 阅读全文
posted @ 2021-03-03 20:18 鑫茂 阅读(301) 评论(0) 推荐(0)
摘要:1. 委托 sequenceDiagram 方法->>委托: 返回值和入参一样 委托->>方法: 调用委托就是调用绑定的方法 delegate int NumTest(int num); int Add(int num) { return num + 10; } void Test() { NumT 阅读全文
posted @ 2021-03-03 20:12 鑫茂 阅读(72) 评论(0) 推荐(0)
摘要:引入 log4net.dll 项目->添加->新建项->应用程序配置文件,命名为 log4net.config,并把属性的复制到输出目录设置为 如果较新则复制,后续客户端需要读取在 debug 下的这个文件; 封装日志类 WriteLog 1. log4net.config <?xml versio 阅读全文
posted @ 2021-03-03 19:58 鑫茂 阅读(277) 评论(0) 推荐(0)
摘要:public static class LogHelper { private static readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory + "VILog"; private static DateTime _cu 阅读全文
posted @ 2021-03-03 19:45 鑫茂 阅读(140) 评论(0) 推荐(0)
摘要:using System.Windows.Forms; ... /// <summary> /// 选择保存文件的名称以及路径 取消返回 空""; /// </summary> /// <param name="fileName"></param> /// <param name="filter"> 阅读全文
posted @ 2021-03-03 19:35 鑫茂 阅读(240) 评论(0) 推荐(0)
摘要:1. string 1. 格式化填充 string str = "this {0} a {1}"; Console.WriteLine(string.Format(str, "is", "boy")); // this is a boy 2. 将数据合并成字符串 string[] strArr = 阅读全文
posted @ 2021-03-03 19:26 鑫茂 阅读(591) 评论(0) 推荐(0)
摘要:这里举例两种方式。 1. Newtonsoft.Json.JsonConvert 需要引用外部的 Newtonsoft.Json.dll /// <summary> /// 将json字符串转换为对象(使用Json.net) /// </summary> /// <param name="respo 阅读全文
posted @ 2021-03-03 19:25 鑫茂 阅读(426) 评论(0) 推荐(0)
摘要:1. 程序根目录: (D:\\...\\WpfApp1\\WpfApp1\\bin\\Debug") string exePath = Environment.CurrentDirectory; 2. 获取该进程的命令行 (\"D:\\...\\WpfApp1\\WpfApp1\\bin\\Debu 阅读全文
posted @ 2021-03-03 19:21 鑫茂 阅读(580) 评论(0) 推荐(0)