By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

vb module equivelent in C#

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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" wrote:
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

Nov 16 '05 #2

P: n/a

"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 16 '05 #3

P: n/a
Thanx Peter. How do you "seal" a class?

"Peter van der Goes" wrote:

"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Nov 16 '05 #4

P: n/a
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" wrote:
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" wrote:
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

Nov 16 '05 #5

P: n/a
"Poewood" <Po*****@discussions.microsoft.com>
:58**********************************@micros oft.com...
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.
Nov 16 '05 #6

P: n/a
"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
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
}

}
Nov 16 '05 #7

P: n/a
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" wrote:
"Poewood" <Po*****@discussions.microsoft.com> ëúá
áäåãòä:58**********************************@ microsoft.com...
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.

Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.