Visual C# Developer Center >
Visual C# Forums
>
Visual C# Language
>
C# equiv of a VB module for global values?
C# equiv of a VB module for global values?
- I am pretty new to VB and C#, I've ignroed them for years and stayed in my C++ world. Now my new job is throwing .NET at me at 100 mph. So, I am digging through code and find that you can create projects in either language and they can work together, but you cannot write both in the same project. So, I am going to need to translate some VB to C#. Anywho, the question is: What is the preferred method of creating some globally accessable values? Also, access of values from the config files?
Answers
- It looks like the answer is to use a sealed/static class. Things move over pretty easy from a global module that way.
There is also app config which can hold alot of settings and such and be parsed using System.Config.ConfigurationManager- Marked As Answer byChristopher Pisz Saturday, November 07, 2009 2:46 AM
All Replies
You can create multi-project, multi-language solutions in Visual Studio.
That means you can VB and C# projects within the same solution.
I see no reason to translate working VB code into C#, unless it is a matter of preference to have it all in one language or another.
What version of VS are you using? Express Editions have limitations that can be worked around.
Globally accessed variables can be created in C# by declaring as static. Not the Object Oriented approach at all.
Use the Properties.Resources and Properties.Settings folders in Solution Explorer.
Mark the best replies as answers. "Fooling computers since 1971."- Using team edition. Well the reason for the translation is that someone wrote a service in VB and I wrote a service in c#, now we need to combine them. There isn't much, just a 15 line onstart, but I have to do all the settings, globals they used, and some encryption of connectrion strings and such.
- Hmmm. Duplicate code?
Why not simply create a separate assembly that both services reference?
Take your pick. Do it in VB or C#?
There are dozens of free code translators out there.
But I find that Reflector from Red Gate does a decent job on single classes.
I useful tool that every developer should have.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."- Marked As Answer byBin-ze ZhaoMSFT, ModeratorFriday, November 06, 2009 3:21 AM
- Unmarked As Answer byChristopher Pisz Saturday, November 07, 2009 2:44 AM
- Not really duplicate. They both do different things, but we want them to run under one service. So yea, I am trying to create a solution with the seperate assemblies. I am splitting off all the actual implementations, interfaces, and such and trying to get a proper organization of things. However, there will only be one service. I guess I got to learn a bit of VB. I'll peruse the MSDN language docs for a bit.
- It looks like the answer is to use a sealed/static class. Things move over pretty easy from a global module that way.
There is also app config which can hold alot of settings and such and be parsed using System.Config.ConfigurationManager- Marked As Answer byChristopher Pisz Saturday, November 07, 2009 2:46 AM
You can create multi-project, multi-language solutions in Visual Studio.
That means you can VB and C# projects within the same solution.
I see no reason to translate working VB code into C#, unless it is a matter of preference to have it all in one language or another.
What version of VS are you using? Express Editions have limitations that can be worked around.
Globally accessed variables can be created in C# by declaring as static. Not the Object Oriented approach at all.
Use the Properties.Resources and Properties.Settings folders in Solution Explorer.
Mark the best replies as answers. "Fooling computers since 1971."
That path leads to code that can quickly become unwieldy.
One small change here or there ripples across multiple methods and classes just ot make it compile again.
The difficult part is that changes you might need to make do not always cause compiler errors. Broken code.
Now you are forced to remember, verify, check every location in your code that might be affected by the original change.
Mark the best replies as answers. "Fooling computers since 1971."


