
假设我已经上课了
public static class LogInitialization { static LogInitialization() { System.Console.Writeline("Initialized"); }} 有没有办法得到这行打印?
请注意,该类是静态的,所以我无法实例化它强制初始化,它没有公共成员,所以我无法访问它们启动它.
解决方法 在Cli规范中进行翻阅,我发现对方法RuntimeHelpers.RunClassConstructor的引用 总结If a language wishes to provIDe more rigID behavior — e.g.,type initialization automatically triggers execution
defining hIDden static fIElds and code in each class constructor that touches the hIDden static fIEld of its
of base class’s initializers,in a top-to-bottom order — then it can do so by either:
base class and/or interfaces it implements,or by making explicit calls toSystem.Runtime.CompilerServices.RuntimeHelpers.runclassConstructor(see Partition IV).
以上是内存溢出为你收集整理的c# – 强制类加载全部内容,希望文章能够帮你解决c# – 强制类加载所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)