合集-C#
摘要:1.浮点数 用于表示数量级可能非常大或者非常小的非整数; float:单精度浮点数表示用于存储值的二进制位数为32位 double:双精度浮点数相对于单精度浮点数而言,是其两倍;即表示用于存储值的二进制位数为64位 2.常见算数运算 int c=7/4; //若值不为整数,商取整 Console.W
阅读全文
摘要:1.列表创建 var names = new List<string> { "博客园", "cc", "efun" ,"zp"}; foreach (var name in names) { Console.WriteLine($"Hello {name.ToUpper()}!"); } Hello
阅读全文
摘要:Queue类将队列实现为循环数组。 queue对象实现了在一端插入并从另一端删除(即先进先出功能)
如存在多个CCD检测情况下,每个ccd检测结果信息存储到Queue中,最后一个ccd检测完成,然后发送数据到robot(plc)等,通过Queue的Dequeue()方法来达到先进先出功能
阅读全文
摘要:IEnumerator接口:支持对非泛型集合的简单迭代,使得foreach可以遍寻集合 using System; using System.Collections; public class Family { private string husban = null; public string
阅读全文
摘要:1.引用 using System; using System.Collections.Generic; using System.Linq; 2.打印一副扑克牌 static void Main(string[] args) { var pokers = from s in Suits() fro
阅读全文
摘要:1.ConcurrentDictionary ConcurrentDictionary 并发字典,保证多线程情况下的安全性 Dictionary 非线程安全集合 using System.Collections.Concurrent; class Program { static void Main
阅读全文
摘要:TextWrapping="Wrap" 不显示滚动条 ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
阅读全文
摘要:非引用类型初始化为空,类型后面加? int? value = null; //在不想指定value一个初始值情况下,指定value为空
阅读全文
摘要:public static async Task Main() { Task<int> downloading = TaskAsync(); Console.WriteLine($"{nameof(Main)}: A"); int bytesLoaded = await downloading; C
阅读全文
摘要:public static void Main() { List<int>? numbers = null; int? a = null; Console.WriteLine((numbers is null)); //true // 如果numbers为空,则初始化numbers,同时添加一个5到
阅读全文
摘要:1.查询一定范围数字 static void QueryInt() { // Specify the data source. int[] scores = { 97, 92, 81, 60 }; // Define the query expression. IEnumerable<int> sc
阅读全文
摘要:using System.Xml.Linq; static void Main(string[] args) { XElement contacts = new XElement("Contacts", new XElement("Contact", new XElement("Name", "Pa
阅读全文
摘要:static void Main(string[] args) { XElement purchaseOrder = XElement.Load("Contacts.xml"); string partNos = (string)(from item in purchaseOrder.Descend
阅读全文
摘要:xml位于命名空间中时查找 static void Main(string[] args) { XElement root = XElement.Parse(@"<aw:Root xmlns:aw='http://www.efun.com'> <aw:Child1> <aw:GrandChild1>
阅读全文
摘要:1.fixed语句 *固定用于指针操作的变量; *可防止垃圾回收器重新定位可移动变量,并声明指向该变量的指针; *固定变量的地址,在语句的持续时间内不会更改 *fixed语句中,只能使用声明的指针,声明的指针是只读的,无法修改 *fixed语句只能在不安全的上下文中使用 static void Ma
阅读全文
摘要:匿名类型: *提供了一种方便的方法,用来将一组只读属性封装到单个对象中,而无需首先显示定义一个类型 *类型名由编译器生成 *结合new运算符和对象初始值设定项创建匿名类型 *匿名类型是class类型,直接派生自object *如下示例,查找年龄是两岁的猫 public class Cat { //
阅读全文
摘要:init关键字: 1.init在属性或索引器中定义访问器方法 2.仅在对象构造期间为属性或索引器元素赋值 3.init强制实施不可变性(对象一旦初始化,将无法更改) 4.如下同时定义get和init访问器 class Person_InitExample { private int _yearOfB
阅读全文