Why a class?

A simple question arose while I was reading the syntax of a simple C# program.
For instance, we know that this is a simple program :

class something
{

static void Main()
{
System.Console.WriteLine("Hey sucker");
}

}

Why does a program start with a class I don't understand why is class before like all of that I thought a class was just like somewhat of a database.


Answer this question

Why a class?

  • Bear23

    a class is not a database. Those are 2 different things altogether. A class is like a module in a sense or rather a "file" which holds all functions or rather all code to execute. This is what a class has. How else would you create code :-)

    Classes is what is used to create applications (several classes in 1 solution = application). It is also what is used to create objects and have an OO application. Its not a small topic to cover but hope you understand this.

     



  • LORD ORION

    To answer you main question, Main() is in a class, because in C# all methods must by in a class, even if, as in the case of class something, the rest of the class is pointless.

    AS to your other statement, ("I thought a class was just like somewhat of a database."), there is a small amount of truth in there, but it needs some explaination.

    First, I'm going to assume that by "database" you meant "a database table" (a "database" is actually a collection of table -- and views, stored procedures, etc --- working together).

    An class isn't a table, but it's not that for off.

    A "object" is some information bundled together to form a single logical concept. It's somewhat like a single row of a database table. A class is the definition of the structure of an object. It's somewhat analogous to the definition of a database table (but not to the table itself -- whopse closest model would be an array of objects)



  • Sam4u2e

    Why not
  • Why a class?