What colon ( : ) means defining a class in c#?

2020-03-01 02:58发布

In c# defining a class what does : means?

As example, in this very basic controller of an ASP.NET MVC application:

namespace App.Controllers
{
    public class HomeController : Controller
    {    
        public ActionResult Index()
        {
            return View();
        }
    }
}

In the third line, what does : Controller means?

2条回答
做自己的国王
2楼-- · 2020-03-01 03:43

In this case it means that the HomeController inherits the Controller class.

You can read more details about inheritance here, but simply put - inheritance means that everything a Controller is, a HomeController is also. A HomeController is a more finely grained Controller class.

It can also be used for implementation of interfaces http://msdn.microsoft.com/en-us/library/ms173156.aspx

查看更多
女痞
3楼-- · 2020-03-01 03:45

The : is used in C# to denote class inheritance or interface implementation. In this case HomeController inherits from the class Controller

查看更多
登录 后发表回答