随笔分类 -  C#

C# 语言
摘要:首先定义一个自定义的属性类MyAttribute,该类需要继承Attribute public class MyAttribute : Attribute { /// <summary> /// 代码 /// </summary> public string Code { get; set; } / 阅读全文
posted @ 2020-11-14 18:58 温故纳新 阅读(9541) 评论(0) 推荐(0)
摘要:需要使用反射调用的类定义如下: class InvokeTest { #region 静态方法 public static void StaticMethod(string para) { Console.WriteLine(para); } #endregion #region 实例方法 publ 阅读全文
posted @ 2020-11-14 17:05 温故纳新 阅读(1393) 评论(0) 推荐(0)
摘要:? 可空(null)类型修饰符 //int x = null; // 错误,变量x不是引用类型 int? xx = null; ? : 三元(运算符)表达式 x ? y : z 表示如果表达式x为true,则返回y;如果x为false,则返回z int y = 1 > 0 ? 10 : 0; // 阅读全文
posted @ 2020-10-12 16:57 温故纳新 阅读(178) 评论(0) 推荐(0)
摘要:1 应用场景介绍 如果拥有一些方法并且想让它们中的一些有默认实现,那么使用抽象类; 如果想实现多重继承,那么必须使用接口。由于一个类只能有一个超类。但是,可以实现多个接口,因此可以使用接口来解决它。 2 举例说明 门和警报——门都有open( )和close( )两个动作,通过抽象类和接口来定义这个 阅读全文
posted @ 2020-09-26 12:37 温故纳新 阅读(161) 评论(0) 推荐(0)
摘要:1 定义PersonModel类 public class PersonModel { public String Id { get; set; } public String UserCode { get; set; } public String UserName { get; set; } p 阅读全文
posted @ 2020-08-30 14:43 温故纳新 阅读(644) 评论(0) 推荐(0)
摘要:访问修饰符 public:同一程序集中的任何其他代码或引用该程序集的其他程序集都可以访问该类型或成员。 private:只有同一 class 或 struct 中的代码可以访问该类型或成员。 protected:只有同一 class 或者从该 class 派生的 class 中的代码可以访问该类型或 阅读全文
posted @ 2020-08-29 22:32 温故纳新 阅读(738) 评论(0) 推荐(0)
摘要:示例代码: static void Main(string[] args) { ResultModel res = new ResultModel(); res.code = 0; res.msg = "初始值"; OtherMehod(res); Console.WriteLine(res.msg 阅读全文
posted @ 2020-08-21 13:52 温故纳新 阅读(655) 评论(0) 推荐(0)
摘要:Dictionary 可以简单的看作是KeyValuePair 的集合; 示例: static void Main(string[] args) { Dictionary<int, string> dics = new Dictionary<int, string>(); dics.Add(1, " 阅读全文
posted @ 2020-08-21 13:33 温故纳新 阅读(1111) 评论(0) 推荐(0)