locked
can you convert this code to vb.net RRS feed

  • Question

  • User-125499312 posted

    or at least please explain so that i can write the equivalent in vb.net 

    string token = string.Empty;

    token = (from extenddata test in response.extenddatalist
     where test.paramname == "securetoken"
     select test.ParamValue).FirstOrDefault();

    thx for ur help

    Wednesday, February 28, 2018 7:45 PM

All replies

  • User-1716253493 posted

    AFAIK, you need to convert this line only

    DIM token as string = string.Empty

    Thursday, March 1, 2018 2:53 AM
  • User-1838255255 posted

    Hi yzidell,

    According to the code, i think these code is a query command in LINQ. 

    response.extenddatalist is a list. 

    test is a abject, paramname is a property of object.  

    it will get a list when test.paramname == "securetoken". 

    FirstOrDefault() method will return the first value of this list. 

    About how to write the VB query command, you could check this tutorial: 

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/linq/writing-your-first-linq-query  

    Best Regards,

    Eric Du 

    Thursday, March 1, 2018 3:14 AM
  • User516094431 posted

    string token = string.Empty;

    token = (from extenddata test in response.extenddatalist
     where test.paramname == "securetoken"
     select test.ParamValue).FirstOrDefault();

    There is issue in code, remove 'test' from code. 

    result of your code is, it's getting first row where paramname = "securetoken" . 

    Note: Row should be contain only string not object. Because you are storing this result into 'token string'.

    C# Code:

    string token = string.Empty;
    
                token = (
                    from extenddata in response.extenddatalist
                    where extenddata.paramname == "securetoken"
                         select extenddata.ParamValue
                         ).FirstOrDefault();

    VB Code:

    Dim token As String = String.Empty
    
    token = (From extenddata In response.extenddatalist _
    	Where extenddata.paramname = "securetoken" _
    	Select extenddata.ParamValue).FirstOrDefault()

    Thursday, March 1, 2018 6:26 AM