Converting from VB .NET to C#

Discussion in 'ASP .Net' started by stephen, Jul 18, 2006.

  1. stephen

    stephen Guest

    I have been working using VB .NET and I wanted to convert a code to C#
    in VB .Net I use modules so that I can declare variables, STP holders so
    that I can replace them easily when I move b/w Dev and Prod like this

    Module modAVSVariables
    'Arraylist and Array Variables
    Friend pathArray As Array
    Friend temp_arrAllFiles As Array
    Friend getPath As ArrayList = New ArrayList

    End Module

    ....................and access them like this in Classes like this:
    Public Class HelperClass
    Friend Function getPaths() As Boolean
    nvc = CType(ConfigurationSettings.GetConfig("Key"),
    For Each key As String In nvc.Keys
    If nvc(key) = "" Then
    _fileError.KeyError("Missing Path", "Key", key)
    Return False


    End If

    Return True

    End Function

    Friend function getFiles() as Boolean
    temp_arrAllFiles = System.IO.Directory.GetFiles(getPath(0))

    End Function

    End Class

    .... and so on....
    whats the equivalent of "module" in C# where i can declare them....

    stephen, Jul 18, 2006
    1. Advertisements

  2. stephen

    Mischa Kroon Guest

    Sharpcode has a super Code translator between VB.Net and C#:

    This will translate it all for you :)
    Mischa Kroon, Jul 18, 2006
    1. Advertisements

  3. stephen

    clintonG Guest

    "C# & VB.NET Conversion Pocket Reference" published by O'Reilly is very
    clintonG, Jul 19, 2006
  4. stephen

    stephen Guest


    stephen, Jul 19, 2006
  5. stephen

    Guest Guest

    A module is basically a class with only static members.
    Our Instant C# VB to C# converter produces the following equivalent C# code:

    internal static class modAVSVariables
    //Arraylist and Array Variables
    internal static Array pathArray;
    internal static Array temp_arrAllFiles;
    internal static ArrayList getPath = new ArrayList();

    public class HelperClass
    internal bool getPaths()
    nvc = (NameValueCollection)(ConfigurationSettings.GetConfig("Key"));
    foreach (string key in nvc.Keys)
    if (nvc(key) == "")
    _fileError.KeyError("Missing Path", "Key", key);
    return false;


    return true;


    internal bool getFiles()
    modAVSVariables.temp_arrAllFiles =

    //INSTANT C# NOTE: Inserted the following 'return' since all code paths
    must return a value in C#:
    return false;


    David Anton
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C#/VB to C++ converter
    C# Code Metrics: Quick metrics for C#
    Guest, Jul 19, 2006
  6. Eliyahu Goldin, Jul 19, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.