4
我需要一个方法返回我一些参数控制器之间,这是实现它:差异ASP.NET MVC静态或NoneStatic方法
public List<Parameter> GetParameters(FormCollection collection) {
List<Parameter> parameters = new List<Parameter>();
List<string> parameterNames = new List<string>();
//Get Parameters Names and Values
return parameters;
}
我在所有控制器都使用这种方法,所以我认为约3选项,我必须进行定义:在静态类如静态方法
public class ProductController : Controller {
public List<Parameter> GetParameters(FormCollection collection) {
//
}
}
2 - 定义它:
1-对于任何控制器类中的是,控制器这样定义它:
public static class GeneralMethods {
public static List<Parameter> GetParameters(FormCollection collection) {
//
}
}
3 - 定义它作为一个没有静态:
public class GeneralMethods {
public List<Parameter> GetParameters(FormCollection collection) {
//
}
}
哪一个更好?哪一个有更好的表现?或者用于定义许多控制器中使用的方法的其他选项? 你的建议是什么?
从表现上看,你不可能注意到三种方法之间的差异。 “更好”是什么意思?为了什么?可用性?可读性?保养?还有别的吗? – Oded 2012-04-21 08:30:22
@Oded我不知道在网络中,哪一个是常见的或性能或页面加载时间或服务器性能的差异 – Saeid 2012-04-21 08:32:37
正如我所说,当涉及到性能时,你将不会有任何明显的差异。 – Oded 2012-04-21 08:34:03