【发布时间】:2016-05-05 16:44:40
【问题描述】:
在 MVC 应用程序中,有几个类使用没有方法体的构造函数。例如其中一个类是 ActionResult 类:
using System;
namespace System.Web.Mvc
{
// Summary:
// Encapsulates the result of an action method and is used to perform a framework-level
// operation on behalf of the action method.
public abstract class ActionResult
{
// Summary:
// Initializes a new instance of the System.Web.Mvc.ActionResult class.
protected ActionResult();
// Summary:
// Enables processing of the result of an action method by a custom type that
// inherits from the System.Web.Mvc.ActionResult class.
//
// Parameters:
// context:
// The context in which the result is executed. The context information includes
// the controller, HTTP content, request context, and route data.
public abstract void ExecuteResult(ControllerContext context);
}
}
此类构造函数没有方法体。 当我尝试在应用程序中复制代码时,我得到了预期的错误,即构造函数需要有一个方法体。
namespace ConsoleApplication1
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public abstract class MyBase
{
protected MyBase();
}
}
在这种情况下,Microsoft 做了什么让对象构造函数以这种方式工作?
【问题讨论】:
标签: c# .net frameworks