随笔分类 - C#语法
摘要: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}
阅读全文
摘要:一.声明一个MyClass对象 public class MyClass { public int MyField; } 二.获取RequiredAttribute类型信息 MyClass instance = new MyClass(); FieldInfo field = instance.Ge
阅读全文
摘要:如果标记了[NonSerialized]特性,会防止将该字段序列化。但是,该字段仍然可以用于foreach迭代,因为它仍然是枚举的有效成员。如果要防止特定枚举成员被foreach迭代,用[NonSerialized]特性是不起作用的。相反,可以创建一个自定义的Attribute继承自System.A
阅读全文
摘要:调用表达式 () 使用括号 () 调用()或调用委托。 以下示例演示如何在使用或不使用参数的情况下调用方法,以及调用委托: Action<int> display = s => Console.WriteLine(s); var numbers = new List<int>(); numbers.
阅读全文
摘要:示例 1:goto 在 switch 语句中的使用 class SwitchTest { static void Main() { Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large"); Console.Write("Please e
阅读全文
摘要:从 C# 7.0 开始,可以使用元组类型和元组文本轻松实现此目的。 元组类型定义元 组元素的数据类型。 元组文本提供返回的元组的实际值。 在下面的示例中, (string, string, string, int) 定义 GetPersonalInfo 方法返回的元组类型。 表达式 (per.Fir
阅读全文
摘要:whereExpression = whereExpression.And(u => u.ValueInterger.ToString() != null &&** u.ValueInterger.ToString()**.Equals(searchPageListDTO.searchCriteri
阅读全文