zoukankan      html  css  js  c++  java
  • C#-类的成员初始化顺序

            public static async Task Main(string[] args)
            {
                new Child();
    
                Console.ReadKey();
                await Task.CompletedTask;
            }
    
            public static class Helper
            {
                public static string ValueWithLog(string s)
                {
                    Console.WriteLine(s);
                    return s;
                }
            }
    
            public class Base
            {
                private static string _baseStaticField = Helper.ValueWithLog($"{nameof(Base)}:{nameof(_baseStaticField)}");
                public static string BaseStaticProperty { get; set; } = Helper.ValueWithLog($"{nameof(Base)}:{nameof(BaseStaticProperty)}");
                
                private string _baseField = Helper.ValueWithLog($"{nameof(Base)}:{nameof(_baseField)}");
                public string BaseProperty { get; set; }= Helper.ValueWithLog($"{nameof(Base)}:{nameof(BaseProperty)}");
                static Base()
                {
                    Helper.ValueWithLog($"{nameof(Base)}:static Base()");
                }
    
                public Base()
                {
                    Helper.ValueWithLog($"{nameof(Base)}:public Base()");
                }
            }
    
            public class Child : Base
            {
                private static string _childStaticField = Helper.ValueWithLog($"{nameof(Child)}:{nameof(_childStaticField)}");
                public static string ChildStaticProperty { get; set; } = Helper.ValueWithLog($"{nameof(Child)}:{nameof(ChildStaticProperty)}");
    
                private string _childField = Helper.ValueWithLog($"{nameof(Child)}:{nameof(_childField)}");
                public string ChildProperty { get; set; } = Helper.ValueWithLog($"{nameof(Child)}:{nameof(ChildProperty)}");
    
                static Child()
                {
                    Helper.ValueWithLog($"{nameof(Child)}:static Child()");
                }
    
                public Child()
                {
                    Helper.ValueWithLog($"{nameof(Child)}:public Child()");
                }
            }

  • 相关阅读:
    FreeSql 教程引导
    Day3-JS-JavaScript 函数专题
    Day2-JS-JSON
    Day2-JS-let和const
    Day2-JS-this 关键字
    Day2-JS-JavaScript 验证 API
    Day2-JS-表单
    Day2-JS-严格模式
    Day2-JS-JavaScript 错误
    Day2-JS-正则表达式
  • 原文地址:https://www.cnblogs.com/LaughAtSelfsWrong/p/13671503.html
Copyright © 2011-2022 走看看