C# class name
How does the class name affect the script in C#? From what I know it acts like classes from C++ and you use the class names as functions are used in Lua. Is this right or am I off base? If this is right how do I create a program using multiple class names?
VulpesPosted Sep 25, 2011, 7:15 PM
Unlike C++, all C# functions (or methods as we prefer to call them) must be members of a class - global functions are not allowed. Even the Main() method has to be a member of a class.
So, a C# program is essentially just a collection of classes. There are other types of entity such as structs and enums but this doesn't affect the basic principle. The order in which the classes are presented is immaterial.
I don't know much about Lua but I believe you can simulate classes using functions and tables to represent the data on which the functions operate. So, there is some truth in what you say.
Here's an example of a very simple C# program with two classes:
using System;
class MyClass
{
private string greeting = "Hello world";
public void GetGreeting()
{
Console.WriteLine(greeting);
}
}
class Program
{
static void Main()
{
MyClass mc = new MyClass();
mc.GetGreeting();
Console.ReadKey();
}
}