How do I create public variables/functions in C#? + Other basic questions

matt_cowdell used Ask the Experts™
I am new to C Sharp .Net and I have a few questions.

I am moving on from VB.Net, and I've noticed a lot of differences.

How am I meant to create public variables, procedures and functions?

In VB.Net I could create a module with a procedure/function in it and call that procedure/function from anywhere in my program. How is this done in C#?

Also, in VB.Net I could go into code, i.e. Form_Open and click the combo box in the top right of Visual Studios 2005 and select from any of the other events like Form_Close. I have found how to add these events I think; by adding them into the designer.cs file of the form. Is this the only way?

And, can someone explain what all the difference public/static/void/etc terms mean and what the VB.Net equivalent (if any!) is?

Thanks in advance!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
public variables, yea u cant like One way to achieve this is to create a static class

static class MyGlobals
    private string m_dummy = "";

    public static string Dummy
        get {
            return m_Dummy;
        set {
            m_Dummy = value;

Now u can reference it like this

something = MyGlobals.Dummy;

In C#, u need to create classes and use them that way instead of defining modules and calling them

Not sure about your event handlers

public means its accessible to the outside world. i.e. public procedure fred
static means a it still exists even when the block of code it was initialised in terminates. U can use static in vb
void means it doesnt return anything, much like a procedure (sub) instead of a function in vb
Commented: is a list of keywords which you can click for definitions and examples. is a list of differences between VB and C#. The differences and usage aren't clearly explained, but it should be a good starting point for what to google. is perhaps a better resource. A lot of the information is available online dotted around msdn, but this provides a nice central document. For some reason it's a downloadable, self extracting doc file :S


Thanks! those explanations are great!
Thanks. Explanations more help full people are moving from to c# like me

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial