分类 编程语言 中的文章

CSharp查缺补漏之重写(override)和覆盖(new)的区别

不管是重写还是覆盖都不会影响父类自身的功能(废话,肯定的嘛,除非代码被改)。 当用子类创建父类的时候,如 C1 c3 = new C2(),重写会改变父类的功能,即调用子类的功能;而覆盖不会,仍然调用父类功能。 虚方法、实方法都可以被覆盖(new),抽象方法,接口 不可以。 抽象方法,接口,标记为virt……

阅读全文

CSharp查缺补漏20210928

c# 7.0 特性 数字字面量的改进 数字字面量可以使用下划线来改善可读性、它们称为数字分隔符而被编译器忽略 1 2 3 int million = 1_000_000; var b = 0b1010_1011_1100_1101_1110_1111; // 二进制字面量可以使用0b前缀进行标识 解构器 解构方法的名字必须为Deconstruct,并且拥有一个或多个out参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class Rectangle { public readonly float Width, Height; public……

阅读全文

使用Activator动态创建实例

Activator Activator 包含能够创建本地或远程类型对象或获取对现有远程对象的引用的方法。 重要的方法 CreateInstance 此方法通过调用与给定参数最匹配的类构造函数创建类的实例。默认情况下,如果被创建实例的类没有Public的构造函数或找不到匹配的构造函数,此方法将抛出异常。……

阅读全文

Lua学习记录(三)

位和字节 位运算 运算符 操作 & 按位与 | 按位或 ~ 按位异或 « 逻辑左移 » 逻辑右移 ~ 按位取反(一元运算) Lua 中没有提供算术右移和左移,只提供了逻辑的。 无符号整数 Lua 中使用 math.ult 函数比较两个无符号整数的大小。 打包和解包二进制数据 string.pack 函数会把值打包成二进制数据 string.unpack 则反之 string.pack 和 string.unpack 的第一个参数是格式化字符串,函数……

阅读全文

Lua学习记录(二)

模式匹配 函数 string.find 返回匹配的开始和结束索引 string.match 返回匹配的字符串 string.gsub 返回替换后的字符串和发生替换的次数 string.gmatch 返回函数,此函数可遍历一个字符串中所匹配的所有字串 模式 Lua 中模式使用百分号做转义字符。 字符分类 含义 . 任意字符 %a 任意字母 %c 控制字符 %d 数字 %g 除空格外的可打印字符 %l 小写字母 %p 标点符号 %s 空白字符 %u……

阅读全文

Lua学习记录(一)

标识符 由任意字母、数字和下划线组成,同时首字符不能是数字,大小写敏感。 下划线加全大写字母(例如:_VERSION)组成的标识符,通常是特殊标识符(最好不要定义相同的标识符)。 一下是 lua 保留字 1 and break do else elseif end false goto for function if in local nil not or repeat return then true until while 注释 以下为单行注释 1 -- 单行注释 以下是多行注释 1……

阅读全文

CSharp中发送HTTP请求的方法

发送 Get 请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks. static readonly HttpClient client = new HttpClient(); static async Task Main() { // Call asynchronous network methods in a try/catch block to handle exceptions. try { HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); // Above three lines can be replaced with new helper method below // string responseBody = await client.GetStringAsync(uri); Console.WriteLine(responseBody); } catch(HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ",e.Message); } } 发送 Post 请求 1 2 3 4 5 6 7 8 9 10 11 using (var httpClient = new HttpClient { BaseAddress = new Uri(cqcPlatformUrl) }) { httpClient.DefaultRequestHeaders.Add("Test", "TestValue");……

阅读全文

CSharp中用线程安全的方式引发事件

在不考虑线程安全的情况下常常会写如下引发事件的代码: 1 2 3 4 5 6 7 // 版本1 public event EventHandle<EventArgs> Something; protected virtual void OnSomething(EventArgs e) { if(Something != null) Something(this, e); } 以上代码在单线程环境下能够正常运行,但是在多线程环境下就有可能导致问题。虽然对 Something 做了空引用的判断,但是在调用 Something 前有可能被另一个线程从委托链中移除委托,使得 Something 为空,导致空引用调……

阅读全文

CSharp中的XML序列化

可 XML 序列化的内容 公有类的公有可读写属性和字段 接口 ICollection 或 IEnumerable 的实现类 XmlElement 对象 XmlNode 对象 DataSet 对象 XML 使用的 Attribute 通常 Xml 元素的名称由类名或成员名称,但是也可以通过 Attribute 去控制。 XmlArrayAttribute 和 XmlArrayItemAttribute XmlArrayAttribute 和 XmlArrayItemAttribute 用于控制数组的序列化。 XmlArrayAttribute 可以指定数组序列化时的 Xml元素名称。 1 2 3 4 public class Group { [XmlArray("TeamMembers")] public Employee[] Employees; } 1 2 3 4 5 6 7 <Group> <TeamMembers> <!-- 如果没有指定……

阅读全文