【发布时间】:2018-04-16 13:25:12
【问题描述】:
如果之前有人问过这个问题,我不放心。没找到。
class Program
{
static void Main(string[] args)
{
new ExampleClass();
ExampleClass example = new ExampleClass();
}
}
class ExampleClass
{
public ExampleClass()
{
//Do Stuff
}
}
第一次初始化更快吗?剂量第二个在编译时得到优化。 (假设从未使用过可变示例)
【问题讨论】:
-
第一行有什么用处?
-
你想优化什么?
-
@Camilo Terevinto 它可能不是很好的编程,但你可以在构造函数中做一些事情。然后将它用作方法。
-
如果构造函数有副作用,那么它真的是糟糕的编程。
-
Might not be good programing but you could do stuff in the constructor.Sorta use it as Method then。为什么要争论可怕的编程实践可能的性能优化/影响/好处/坏处。即使出于好奇而对此进行辩论,这种讨论的“要点”是什么?我的意思是,除了“无论性能影响如何,这都是可怕的做法。不要那样做!”...?
标签: c# performance compilation