I know this could be silly, but would like gurus to clarify it for me… Why is this method defined as static ..
public class MvcApplication : System.Web.HttpApplication
{
/* Why this method is declared as static? */
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
its static because it has no need to be a method directly related to instances of the class, but rather a method that can be used in a static context.
In other words, it only affects the parameter “routes”, it doesn’t use any class fields or members, so it makes sense it be made static.