Lost in Translation

Discussion in 'ASP .Net Building Controls' started by jonefer, May 28, 2007.

  1. jonefer

    jonefer Guest

    Please help, I'm using a converter to translate some C# code.

    The following code written in C# does not translate well to Visual Basic
    (If I paste it in a C# page, however it has no problems compiling)

    //C# Code.....

    private string GridViewSortDirection
    {
    get { return ViewState["SortDirection"] as string ?? "ASC"; }
    set { ViewState["SortDirection"] = value; }
    }


    private string GridViewSortExpression
    {
    get { return ViewState["SortExpression"] as string ?? string.Empty; }
    set { ViewState["SortExpression"] = value; }
    }

    ' Here is the VB equivalent

    Private Property GridViewSortDirection() As String
    Get
    Return ViewState("SortDirection") as String ?? "ASC"
    End Get
    Set (ByVal Value As String)
    ViewState("SortDirection") = value
    End Set
    End Property



    Private Property GridViewSortExpression() As String
    Get
    Return ViewState("SortExpression") as String ?? String.Empty
    End Get
    Set (ByVal Value As String)
    ViewState("SortExpression") = value
    End Set
    End Property

    '----------------------------------------------------------------
    ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    ' Developed by: Kamal Patel (http://www.KamalPatel.net)
    '----------------------------------------------------------------
     
    jonefer, May 28, 2007
    #1
    1. Advertising

  2. jonefer

    Guest

    Vb.Net 2.0 or earlier does not have the coalesce operator (double
    question mark).
    So you'll need to write it out like so:

    Get
    Dim o As Object = ViewState("SortExpression")
    If o Is Nothing Then
    Return String.Empty
    Else
    Return CStr(o)
    End If
    End Get

    On May 28, 8:56 pm, jonefer <> wrote:
    > Please help, I'm using a converter to translate some C# code.
    >
    > The following code written in C# does not translate well to Visual Basic
    > (If I paste it in a C# page, however it has no problems compiling)
    >
    > //C# Code.....
    >
    > private string GridViewSortDirection
    > {
    > get { return ViewState["SortDirection"] as string ?? "ASC"; }
    > set { ViewState["SortDirection"] = value; }
    > }
    >
    > private string GridViewSortExpression
    > {
    > get { return ViewState["SortExpression"] as string ?? string.Empty; }
    > set { ViewState["SortExpression"] = value; }
    > }
    >
    > ' Here is the VB equivalent
    >
    > Private Property GridViewSortDirection() As String
    > Get
    > Return ViewState("SortDirection") as String ?? "ASC"
    > End Get
    > Set (ByVal Value As String)
    > ViewState("SortDirection") = value
    > End Set
    > End Property
    >
    > Private Property GridViewSortExpression() As String
    > Get
    > Return ViewState("SortExpression") as String ?? String.Empty
    > End Get
    > Set (ByVal Value As String)
    > ViewState("SortExpression") = value
    > End Set
    > End Property
    >
    > '----------------------------------------------------------------
    > ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    > ' Developed by: Kamal Patel (http://www.KamalPatel.net)
    > '----------------------------------------------------------------
     
    , May 29, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geni[X]MeN
    Replies:
    0
    Views:
    388
    Geni[X]MeN
    Jun 10, 2004
  2. Kieran Francisco

    Timing Diagram to HDL Translation

    Kieran Francisco, Sep 8, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,316
    VhdlCohen
    Sep 17, 2003
  3. Replies:
    0
    Views:
    2,715
  4. Jim Heavey

    C# to VB Translation

    Jim Heavey, Dec 2, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    421
    Jim Heavey
    Dec 3, 2003
  5. Simon Harvey

    Error message translation

    Simon Harvey, Feb 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    Marina
    Feb 5, 2004
Loading...

Share This Page