Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

In vb.net I can do this and thus have a global varaible,

how would I acheive this in C#?

 

Module Main

Public g_ConnStrings As NWDSAConnStrings

End Module

 

 

Thanks

Zack

  • *Experts*
Posted

I tend to stay away from using modules at all; if you use a shared

(static, in C#) variable in a class, you can access it without needing an instance

of the class.

 

In Class1,

public static NWDSAConnStrings g_ConnStrings;

Then in Class2 you can either access it with

Class1.g_Connstrings

or add a using statement at the top

of the class like this:

using MyNamespaceName.Class1;

and then just simply access

'g_Connstrings' like you would as if it was in a module.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...