Explain piece of C# code and conversion to VB.NET -


yesterday asked question. rubens farias answered pointing piece of code wrote. following part of cannot compiled ms visual studio 2010 professional beta 2.

byte[] buffer =  encoding.utf8.getbytes(     string.join("&",          array.convertall<keyvaluepair<string, string>, string>(             inputs.toarray(),             delegate(keyvaluepair item)             {                 return item.key + "=" + httputility.urlencode(item.value);             }))); 

it gives these errors in visual studio. unfortunately rubens doesn't reply anymore.

so have following questions / requests:

  1. i don't understand piece of code, please explain happening exactly.
  2. please explain how part has te rewritten in order "work" in vs.
  3. please explain how should convert vb.net. have tried using online converters no avail.

  • keyvaluepair requires 2 type arguments. in delegate declaration says keyvaluepair item, no type arguments. change delegate(keyvaluepair<string,string> item)
  • httputility declared in system.web namespace; add using system.web; using statements in beginning of file.

personally find easier , cleaner use lambda style kind of code:

byte[] buffer =      encoding.utf8.getbytes(          string.join("&",              array.convertall<keyvaluepair<string, string>, string>(                  inputs.toarray(), (item) => item.key + "=" + httputility.urlencode(item.value)))); 

once have gotten c# code work, developerfusion c# vb.net converter job:

' converted delegate style c# implementation ' dim buffer byte() = encoding.utf8.getbytes( _     [string].join("&", _     array.convertall(of keyvaluepair(of string, string), string)(inputs.toarray(), _         function(item keyvaluepair(of string, string)) (item.key & "=") + httputility.urlencode(item.value))))  ' converted lambda style c# implementation ' dim buffer byte() = encoding.utf8.getbytes( _     [string].join("&", _     array.convertall(of keyvaluepair(of string, string), string)(inputs.toarray(), _         function(item) (item.key & "=") + httputility.urlencode(item.value)))) 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -