I'm beginning to learn C# and I come from a C++ background. The example page I was supposed to create by these instructions looks like
using System.Web;
using System.Web.Mvc;
namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
//
// GET: /HelloWorld/
public string Index()
{
return "This is my <b>default</b> action...";
}
//
// GET: /HelloWorld/Welcome/
public string Welcome()
{
return "This is the Welcome action method...";
}
}
}
My main question is why the HelloWorldController
class is prefixed by public
. I understand that HelloWorldController
is derived from Controller
, but why does a class need to be public
in the first place? My understanding of the words public
and private
is that they only have meaning if they're functions inside a class, and that public
are the ones that can be used by instances of that class. Also, where is my main.cs
in this Visual Studio ASP.NET MVC project that I created?