tags:

views:

109

answers:

2

i am new to asp.net.Can you post an equivalent vb.net code following the C#.net code. Thanks

public string  getSecureCookie(HttpRequest Request)
{
    HttpCookie secureCookie = Request.Cookies["Test"];
        if(secureCookie!=null)
    {
     return secureCookie.ToString();
    }
    else
        {
            return "";
    }
}
+2  A: 

Try this

Public Function getSecureCookie(ByVal request as HttpRequest) As String
  Dim cookie = request.Cookies("Test")
  if cookie IsNot Nothing Then
    return cookie.ToString()
  Else
    return ""
  End If
End Function
JaredPar
Beat me by a couple minutes. I'd give you +1 but I'm out of votes!
lc
@lc, it happens. I don't mind loosing to a correct answer ;)
JaredPar
+5  A: 

Run through the code translator available at http://www.carlosag.net/Tools/CodeTranslator/

Public Function getSecureCookie(ByVal Request As HttpRequest) As String
    Dim secureCookie As HttpCookie = Request.Cookies("Test")
    If (Not (secureCookie) Is Nothing) Then
        Return secureCookie.ToString
    Else
        Return ""
    End If
End Function

Might want to use If secureCookie IsNot Nothing instead, though. But the translator does work.

lc
It's a bit more idiomatic to use IsNot Nothing in VB as opposed to "Not (test) is Nothing)"
JaredPar
Yeah, I just caught that myself...I just pasted the output of the translator directly without wanting to edit it though.
lc