我有两个关于使代码更快的问题,以及某些事情会减慢我的程序的速度。
首先,方法参数。假设我有一个程序,它有一个名为 Account 的基类,然后我创建了该类 Account 的许多实例。在该类中,它有一个名为 Example 的方法,其中包含大量方法参数。这样做很慢吗?对这些东西进行硬编码是否更快,如果有的话?例子:
public class Example
{
public void DoSomething(string One, string Two, string Three, string Four, string Five, string Six, string Seven, string Eight, string Nine, string Ten, string Eleven)
{
// make a WebRequest using these parameters.
}
}
其次,拥有一个内部只有一个成员的类是不是很糟糕,一个基类的实例,如 Example(上图)。例如:
static class ExampleOne
{
public static Example example = new Example();
}
然后像这样使用它:
static void Main(string[] args)
{
ExampleOne.example.DoSomething(parameters);
}
谢谢你的帮助!