"Arjen" <bo*****@hotmail.com> wrote:
C# doesn't knows functions, procedures and contructors?
Thanks!
In Delphi (formerly known as Object Pascal), a function is a routine
that explicitly returns a value, and a procedure is a routine which
doesn't. I'm presuming this is what you mean here.
In C#, you can only define *methods*, which are functions or routines
of a class.
You can define either instance methods or static methods. Instance
methods are called upon an instance of a class, whereas static methods
aren't.
Static methods are, in a sense, functions/procedures which need to be
called with the *class name* as a prefix.
Here:
namespace MyNamespace
{
public class MyClass
{
public static void Procedure()
{
}
public static int Function()
{
}
}
You can call either of these like:
MyClass.Procedure();
MyClass.Function();
Note that you are *not* creating an instance of MyClass here, you are
simply calling its static methods.
As for constructors, C# has them, and their meaning is similar to
those of other languages:
public class MyClass
{
void MyClass()
{
Console.WriteLine("I am a constructor of MyClass!");
}
}
This is similar to the following Delphi code:
interface
type TMyClass = class
public
constructor Create;
end;
implementation
constructor TMyClass.Create;
begin
WriteLn("I am a constructor of TMyClass!");
end;