vb module equivelent in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I store all my global functions in modules when using vb. What is the
equivelent convention in C#. I am converting a .net compact frmwk project
from vb to C#.

Thanx,
Poe
 
You can't have a module, which I think is a good thing. Everything has to be
in a class. Static members are accessible without creating an instance of the
class, and constants are obviously static. So just have a class called
'Consts', and say:
public class consts
{
public const string APP_NAME = "TheApp";
}

public class Class1
{
[STAThread]
public static void Main(string[] args)
{
Console.WriteLine("I'm {0}", Consts.APP_NAME);
}
}
 
Poewood said:
I store all my global functions in modules when using vb. What is the
equivelent convention in C#. I am converting a .net compact frmwk project
from vb to C#.

Thanx,
Poe

In addition to what Patty has told you, I would consider making the class
sealed, so it cannot be used as a base class. Declare all your methods
static, so calls can be qualified with the class name.
 
Thanx Peter. How do you "seal" a class?



Peter van der Goes said:
In addition to what Patty has told you, I would consider making the class
sealed, so it cannot be used as a base class. Declare all your methods
static, so calls can be qualified with the class name.
 
Merci beaucoup Patty!!! You're a great help.

Another question: If I want to declare Static functions, do I have to
include the constant "[STAThread]".



Patty O'Dors said:
You can't have a module, which I think is a good thing. Everything has to be
in a class. Static members are accessible without creating an instance of the
class, and constants are obviously static. So just have a class called
'Consts', and say:
public class consts
{
public const string APP_NAME = "TheApp";
}

public class Class1
{
[STAThread]
public static void Main(string[] args)
{
Console.WriteLine("I'm {0}", Consts.APP_NAME);
}
}


Poewood said:
I store all my global functions in modules when using vb. What is the
equivelent convention in C#. I am converting a .net compact frmwk project
from vb to C#.

Thanx,
Poe
 
Poewood said:
Merci beaucoup Patty!!! You're a great help.

Another question: If I want to declare Static functions, do I have to
include the constant "[STAThread]".
[STAThread] is NOT a constant, rather it's an attribute applied to to the
static Main method.
It has no bearing on the static class 'consts' as shown in Patty's example.
 
Poewood said:
Thanx Peter. How do you "seal" a class?

By using the *sealed* reserverd word e.g.

namespace myNameSpace
{

public class CSealedNo
{
// do something
}

public sealed class CSealedYes
{
// do something else
}

}
 
It was just to try and illustrate that this function is intended to represent
the entry point function that's given to you by the IDE.



Opher Shachar said:
Poewood said:
Merci beaucoup Patty!!! You're a great help.

Another question: If I want to declare Static functions, do I have to
include the constant "[STAThread]".
[STAThread] is NOT a constant, rather it's an attribute applied to to the
static Main method.
It has no bearing on the static class 'consts' as shown in Patty's example.
 
Back
Top