随笔分类 - c#
摘要:创建SyncingClass类,继承与ContextBoundObject,并标记Synchronization特性; 需实现上下文同步的实例必须继承ContextBoundObject和标记Synchronization特性; using System; using System.Threadin
阅读全文
摘要:几个基本类型都有TryParse方法,将object 自动识别类型和转换 using System.Reflection; public static bool TryParse<T>(object val, out T t) { t = default(T); if (val == null) {
阅读全文
摘要:Enumerable.Range(0, 20).Select(i => { long x = 1; for (int j = 1; j <= i; j++) { x *= j; } Console.WriteLine(i + "计算完成"); return x; }); 当你尝试运行上面的代码,会发
阅读全文
摘要:一、XML的序列化 using System.Xml.Serialization; https://www.cnblogs.com/KeithWang/archive/2012/02/22/2363443.html 1.建立序列化测试对象 [XmlRootAttribute("City", Name
阅读全文
摘要:1.个人类Person public class Person { public Person(string fName, string lName) { this.FirstName = fName; this.LastName = lName; } public string FirstName
阅读全文
摘要:using System.Collections.Generic; using System.Configuration; //有可能可以using但不能用,需重新添加引用 /// <summary> /// 针对配置文件的读写操作 (App.config) /// ps:key和name都不区分大
阅读全文
摘要:C#是静态语言,那C#能不能像python一样动态编程呢??? 1.DynamicObject using System; using System.Collections.Generic; using System.Dynamic; using System.Reflection; class P
阅读全文
摘要:占位符 格式化 结果 描述 string.Format("{0,4}", 0) 0 不满足指定位数的情况下,在前置插入空格 string.Format("{0,-4}", 0) 0 不满足指定位数的情况下,在后置插入空格 数字格式化 格式化 结果 格式符 描述 string.Format("{0:0
阅读全文
摘要:一、效果Gif 二、Mark块 public partial class Block : UserControl { public Block() { this.Size = new Size(60, 60); MinFontSize = 4; MaxFontSize = 40; } /// <su
阅读全文
摘要:一、抽象(abstract) 只有类(class)才可以抽象,结构体(struct)不能 ,抽象类不能实例化 class Program { abstract class People { } static void Main(string[] args) { People people = new
阅读全文
摘要:开发工具:VS2019 目的:开启一个服务监听端口进行以太网通讯 一.创建 Windows服务项目 1.创建项目 创建成功后,如下图所示 将 Service1.cs 改名为 BridgeService.cs 双击 BridgeService.cs 后如下图所示 2.添加安装程序 在上图中按中鼠标右键
阅读全文
摘要:using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; namespace ConsoleApp { class Prog
阅读全文
摘要:using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Reflection; using System.Text; using System
阅读全文
摘要:当使用BinaryFormatter进行序列化时实现深复制时,发现如果对象带有公共事件时,会引起报错。 using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters
阅读全文
摘要:事件相当于是对委托的封装,用法是一样的。 例如:有委托 Action act 1.同步触发 同步触发有两种: 直接和方法一样调用:act();调用委托的Invoke方法:act.Invoke(); PS:如果委托订阅了多个方法,是根据订阅的顺序依次触发。 2.异步触发 异步触发是调用委托的Begin
阅读全文
摘要:using System; using System.Collections.Generic; using System.Linq; static class ExtensionMethod { public static IEnumerable<T> Random<T>(this IEnumera
阅读全文
摘要:void PrintPanel() { int paperWidth = 178; int paperHeight = 52; var printDocument = new System.Drawing.Printing.PrintDocument(); //指定打印机 //printDocume
阅读全文
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp4 { class Prog
阅读全文
摘要:语言版本 发布时间 .NET Framework要求 C# 1.0 2002.1 .NET Framework 1.0 C# 1.1\1.2 2003.4 .NET Framework 1.1 C# 2.0 2005.11 .NET Framework 2.0 C# 3.0 2007.11 .NET
阅读全文
摘要:1.使用反射需引用 using System.Reflection; 2.创建用于反射的对象 class People { string _name = "1"; //私有字段 public string Name = "2"; //公共字段 public int Age { get; set; }
阅读全文

浙公网安备 33010602011771号