本文介绍了初始化静态只读方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 我是c#的新手。我有一些基本的编程疑惑。请帮助我 澄清这些疑惑。 我想初始化一个静态和只读字段,返回值 by静态方法。但是,当我调试时,该方法不是被调用的。所以我无法弄清楚,该领域是否正确地进行了初始化。请解释一下这种行为 提前致谢 解决方案 Hello Mark 感谢您的快速回复。我正在考虑当包含静态只读字段的类的新 对象实例化为时。举一个代码示例: class A { private static char [] temp = myFunc(); private const i = 9; private static char [] myFunc() { } 内部A { } } myFunc()返回char []最后。 我试图创建一个A类对象。当控件转到构造函数时,myFunc()没有被调用。 Hello,I am new to c# . I have some basic programming doubts. Please help mein clarifying these doubts.I want to initialize a static and readonly field with a value returnedby a static method. How ever, when I am debugging, that method is notbeing called. So I am not able to figure out, whether the field isgetting initialized properly or not. Please explain this behaviorThanks in advance 解决方案Hello MarkThanks for the quick response. I was looking at the point when a newobject of the class containing the static readonly field is beinginstantiated. To give a code example:class A{private static char[] temp = myFunc();private const i = 9;private static char[] myFunc(){}internal A{}}myFunc() returns the char[] at the end.I was trying to create an object of class A. When the control goes tothe constructor, myFunc() is not being called. 这篇关于初始化静态只读方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!