Converting from VB .NET to C#

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

  1. stephen

    stephen Guest

    Hi,
    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"),
    NameValueCollection)
    For Each key As String In nvc.Keys
    If nvc(key) = "" Then
    _fileError.KeyError("Missing Path", "Key", key)
    Return False

    Else
    getPath.Add(nvc(key))

    End If

    Next
    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....

    Thanks,
    Stephen
     
    stephen, Jul 18, 2006
    #1
    1. Advertisements

  2. stephen

    Mischa Kroon Guest

    Sharpcode has a super Code translator between VB.Net and C#:
    http://www.icsharpcode.net/OpenSource/SD/Default.aspx

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

  3. stephen

    clintonG Guest

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

    stephen Guest

    Thanks

     
    stephen, Jul 19, 2006
    #4
  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;

    }
    else
    modAVSVariables.getPath.Add(nvc(key));

    }
    return true;

    }

    internal bool getFiles()
    {
    modAVSVariables.temp_arrAllFiles =
    System.IO.Directory.GetFiles(modAVSVariables.getPath[0]);

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

    }

    --
    David Anton
    www.tangiblesoftwaresolutions.com
    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
    #5
  6. Eliyahu Goldin, Jul 19, 2006
    #6
    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.