Convert VB.Net Code to C#

Good Afternoon,

I need to rewrite an application from VB.Net to C#. I don't know any C# but guess I will learn along the way. i am using a converter (http://converter.telerik.com/) to convert my module but the converter doesn't appear to convert everything.

I've created a class for my functions (since modules are not used in C#) and am having trouble converting the below to C#, can someone help me rewrite it?

Imports Microsoft.Win32

Module modGlobals

    'Global Registry 
    Public gRegKeyName As String = "HKEY_CURRENT_USER\Software\AFA\TOOLEX"

    Public Function gConnString() As String

        'Global Access Database
        Dim DBPath As String
        DBPath = My.Computer.Registry.GetValue(gRegKeyName, "DBPath", "")

        gConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & ";Persist Security Info=False;"

        Return gConnString

    End Function

    Public Function gCSVExport() As String

        'Global CSV Export Path
        Dim ExportPath As String
        ExportPath = My.Computer.Registry.GetValue(gRegKeyName, "ExportPath", "")

        Return ExportPath

    End Function

End Module

Open in new window


Also what syntax would I use to call these functions from within my application?

Any help would be most appreciated.

Kind Regards,
N
LVL 1
KevinInformation TechnologyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
what is the issue? I have used the converter and without generating 100% pure c# code it really helps getting to speed.

Your issue here might be that there is no direct equivalent to the VB.net Module in C#. You will probably need it to a public static class.
it_saigeDeveloperCommented:
Perhaps something like:
using System;
using Microsoft.Win32;

namespace EE_Q28738647
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("ConnectionString: {0}", Globals.ConnectionString());
			Console.WriteLine("ExportPath: {0}", Globals.CSVExport());
			Console.ReadLine();
		}
	}

	static class Globals
	{
		private const string RegKeyName = @"HKEY_CURRENT_USER\Software\AFA\TOOLEX";

		public static string ConnectionString()
		{
			string dbPath = (string)Registry.GetValue(RegKeyName, "DBPath", "");
			return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;", dbPath);
		}

		public static string CSVExport()
		{
			return (string)Registry.GetValue(RegKeyName, "ExportPath", "");
		}
	}
}

Open in new window


-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KevinInformation TechnologyAuthor Commented:
Thanks. Looks like I need to hit the books as well to get a better understanding.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.