説明のC#コードへの転換VB.NET
-
23-09-2019 - |
質問
昨日、私はこの 質問. ルーベンFarias 回答ではフィルムにこの 作品コード ったものを書く。ついて、下記のとおり計画の一部ではできないよMS Visual Studio2010のプロBeta2.
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);
})));
この これらの 誤りがないようにした。残念ながらルーベンスしない回答なくなった。
いて以下の質問/ように要求を処理します。
- かわからないこの作品のコードを教えてください何が起きているそうですね。
- していくようにこの部て書き換えられするために、ワークVS.
- 教えてくださいどういう構成に変換すVB.NET.しかし使い分けオンライン-コンバータに無い.
解決
- KeyValuePairる型の引数になります。お代表の宣言というだけで
KeyValuePair item
, のない型の引数になります。変更delegate(KeyValuePair<string,string> item)
HttpUtility
宣言され、System.Web
名前空間;追加using System.Web;
の利用の諸表の初のファイルです。
個人的に見やすくなり、クリーナー用ラムダスタイルのためこのようなコード:
byte[] buffer =
Encoding.UTF8.GetBytes(
String.Join("&",
Array.ConvertAll<KeyValuePair<string, string>, string>(
inputs.ToArray(), (item) => item.Key + "=" + HttpUtility.UrlEncode(item.Value))));
一度にいただいており、C#のコードの DeveloperFusion C#るVB.NET コンバーターのお仕事
' Converted from delegate style C# implementation '
Dim buffer As Byte() = Encoding.UTF8.GetBytes( _
[String].Join("&", _
Array.ConvertAll(Of KeyValuePair(Of String, String), String)(inputs.ToArray(), _
Function(item As KeyValuePair(Of String, String)) (item.Key & "=") + HttpUtility.UrlEncode(item.Value))))
' Converted from Lambda style C# implementation '
Dim buffer As Byte() = Encoding.UTF8.GetBytes( _
[String].Join("&", _
Array.ConvertAll(Of KeyValuePair(Of String, String), String)(inputs.ToArray(), _
Function(item) (item.Key & "=") + HttpUtility.UrlEncode(item.Value))))
他のヒント
byte[] buffer =
Encoding.UTF8.GetBytes(
String.Join("&",
Array.ConvertAll<KeyValuePair<string, string>, string>(
inputs.ToArray(),
delegate(KeyValuePair<string, string> item)
{
return item.Key + "=" + System.Web.HttpUtility.UrlEncode(item.Value);
})));
います。
このコードが表示されるビルはGETリクエストのリスト項目例
key1=value1&key2=value2
.この最初の転換inputs
配列の各要素key=value
そのString.Join
ングすることによってこそ、は、アンパサンド.ることができ、UTF-8バイト配列。この作品を参照コードとします。
したらいいと思います。VB.NET プログラマー、申し訳ございません、あなたの思いました。
これは、文字列にキー/値のペアを含む入力リストを変換している多くのクエリ文字列のように見える(例えば。ITEM1 = VALUE1&ITEM2 =値2)、その後、UTF8エンコーディングを使用してバッファのバイト配列にすることを変換します。
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim inputs As New List(Of KeyValuePair(Of String, String))
inputs.Add(New KeyValuePair(Of String, String)("a", "adata"))
Dim buffer As Byte() = _
Encoding.UTF8.GetBytes( _
String.Join("&", _
Array.ConvertAll(Of KeyValuePair(Of String, String), String)( _
inputs.ToArray(), _
Function(item As KeyValuePair(Of String, String)) _
item.Key & "=" & HttpUtility.UrlEncode(item.Value) _
)))
End Sub
End Class
所属していません StackOverflow