Translate to C# from vb

How can i translate the following Class from ASP Classic vb to a C#.net Class

I am just learning C# translating between languages is beyond my capabilities at the moment i have no knowledge of VB

Thank you
Class ASPObjects
 
    'returns Request object variables
    'QType here represents a collection
    '   (QueryString, Form or <A class=iAs style="FONT-WEIGHT: normal; FONT-SIZE: 100%; PADDING-BOTTOM: 1px; COLOR: darkgreen; BORDER-BOTTOM: darkgreen 0.07em solid; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" href="#" target=_blank itxtdid="3809288">Server</A>(ServerVariables))
    Public Function GetRequestVariable(ByVal Key, ByVal QType)
        Select Case lcase(QType)
            Case "session"
                GetRequestVariable = CStr(session(Key))
            Case "querystring"
                GetRequestVariable = CStr(Request.QueryString(Key).Item)
            Case "form"
                GetRequestVariable = CStr(Request.Form(Key).Item)
            Case "server"
                GetRequestVariable = CStr(Request.ServerVariables(Key).Item)
            Case Else
                GetRequestVariable = CStr(Request(Key).Item)
        End Select
    End Function
 
    'returns Session object variables
    Public Function GetSessionVariable(ByVal Key)
        GetSessionVariable = Session(Key)
    End Function
 
    'sets Session object variable
    Public Function SetSessionVariable(ByVal Key, ByVal Value)
        Session(Key) = Value
        SetSessionVariable = ""
    End Function
 
    Public Function encodeURL(ByVal p_string)
        encodeURL = server.urlencode(p_string)
    End Function
 
End Class

Open in new window

LVL 3
QuinnDesterAsked:
Who is Participating?
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.

jinalCommented:

public class ASPObjects
{
    static ASPObjects()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    public static string GetRequestVariable(string key, string Qtype)
    {
        string returnVariable = string.Empty;
        switch (Qtype.ToLower())
        {
            case "session":
                returnVariable = HttpContext.Current.Session[key].ToString();
                break;
            case "querystring":
                returnVariable = HttpContext.Current.Request.QueryString[key];
                break;
            case "form":
                returnVariable = HttpContext.Current.Request.Form[key];
                break;
            case "server":
                returnVariable = HttpContext.Current.Request.ServerVariables[key];
                break;
            default:
                returnVariable = HttpContext.Current.Request[key];
                break;
        }
        return returnVariable;
    }
 
    public static string EncodeUrl(string p_string)
    {
        return HttpUtility.UrlEncode(p_string);
    }
 
    public static string GetSessionVariable(string key)
    {
        if (HttpContext.Current.Session[key] != null)
        {
            return HttpContext.Current.Session[key].ToString();
        }
        else
        {
            return "";
        }
    }
 
    public static void SetSessionVariable(string key, object value)
    {
        HttpContext.Current.Session[key] = value;
    }
}

Open in new window

0

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
jinalCommented:
Hello ,

You can use above class as simple

string  encodeURL = ASPObjects.EncodeUrl("http://www.expert-exchange.com");

I created static class for that. You want to go like

ASPObjects obj = new ASPObjects();
obj.EncdoeUrl("");
then use attached class with this comment.

using System;
using System.Collections.Generic;
using System.Web;
 
/// <summary>
/// Summary description for Class1
/// </summary>
public class ASPObjects
{
    public ASPObjects()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    public string GetRequestVariable(string key, string Qtype)
    {
        string returnVariable = string.Empty;
        switch (Qtype.ToLower())
        {
            case "session":
                returnVariable = HttpContext.Current.Session[key].ToString();
                break;
            case "querystring":
                returnVariable = HttpContext.Current.Request.QueryString[key];
                break;
            case "form":
                returnVariable = HttpContext.Current.Request.Form[key];
                break;
            case "server":
                returnVariable = HttpContext.Current.Request.ServerVariables[key];
                break;
            default:
                returnVariable = HttpContext.Current.Request[key];
                break;
        }
        return returnVariable;
    }
 
    public string EncodeUrl(string p_string)
    {
        return HttpUtility.UrlEncode(p_string);
    }
 
    public string GetSessionVariable(string key)
    {
        if (HttpContext.Current.Session[key] != null)
        {
            return HttpContext.Current.Session[key].ToString();
        }
        else
        {
            return "";
        }
    }
 
    public void SetSessionVariable(string key, object value)
    {
        HttpContext.Current.Session[key] = value;
    }
}

Open in new window

0
jinalCommented:
Hello,

This is code file.

ASPOjects.cs.txt
0
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.