Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 681
Ricardo Polo Jaramillo Avatar asked Mar 03 '12 20:03

Ricardo Polo Jaramillo


People also ask

What Does a colon mean in C?

It's commonly used to pack lots of values into an integral type. In your particular case, it defining the structure of a 32-bit microcode instruction for a (possibly) hypothetical CPU (if you add up all the bit-field lengths, they sum to 32).

What is colon after class name in C#?

The base class is specified by adding a colon, “:”, after the derived class identifier and then specifying the base class name. Note: C# supports single class inheritance only. Therefore, you can specify only one base class to inherit from.


1 Answers

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

like image 178
Rebecca Chernoff Avatar answered Sep 19 '22 22:09

Rebecca Chernoff