转换一个VB code到C# [英] Converting a VB code to C#

查看:354
本文介绍了转换一个VB code到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力理解这VB code,我试图构建一个用于通信的蓝牙连接的应用程序,任何人都可以请帮我TI转换为C#这样我就可以正确地理解它。

I've been struggling to understand this VB code, I'm trying to build a application that uses Bluetooth connection for communication, can anyone please help me to convert ti to C# so I can understand it properly.

    ' The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
' and the file part is the OBEX object name.
Dim addr As String = "112233445566"
Dim uri As New Uri("obex://" & addr & "/HelloWorld.txt")
Dim req As New ObexWebRequest(uri)
req.ReadFile("Hello World.txt")
Dim rsp As ObexWebResponse = CType(req.GetResponse(),ObexWebResponse)
Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode)



    ' The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
' and the file part is the OBEX object name.
Dim addr As String = "112233445566"
Dim uri As New Uri("obex://" & addr & "/HelloWorld2.txt")
Dim req As New ObexWebRequest(uri)
Using content As Stream = req.GetRequestStream()
   ' Using a StreamWriter to write text to the stream...
   Using wtr As New StreamWriter(content)
      wtr.WriteLine("Hello World GetRequestStream")
      wtr.WriteLine("Hello World GetRequestStream 2")
      wtr.Flush()
      ' Set the Length header value
      req.ContentLength = content.Length
   End Using
   ' In this case closing the StreamWriter also closed the Stream, but ...
End Using
Dim rsp As ObexWebResponse = CType(req.GetResponse(),ObexWebResponse) 
Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode)



    Dim lsnr As New ObexListener(ObexTransport. Bluetooth)
lsnr.Start()
' For each connection
Dim ctx As ObexListenerContext = lsnr.GetContext()
Dim req As ObexListenerRequest = ctx.Request
Dim pathSplits() As String = req.RawUrl.Split('/')
Dim filename As String = pathSplits(pathSplits.Length – 1)
req.WriteFile(filename)
'
lsnr.Stop()




    Dim addr As BluetoothAddress _
  = BluetoothAddress.Parse("001122334455")
'
Dim ep As New BluetoothEndPoint(addr, BluetoothService.SerialPort)
Dim cli As New BluetoothClient
cli.Connect(ep)
Dim peerStream As Stream = cli.GetStream()
peerStream.Write/Read ...

在此先感谢!

推荐答案

只需在你的VB.NET code粘贴,这免费的实用工具会自动将其转换为等值的C#。

Simply paste in your VB.NET code , and this free utility will automatically convert it to its equivalent in C#.

刚刚经历 VB.Net到C#

或任何其他在线code转换器。 VB.Net - > C#

or any other online code translator. VB.Net -> C#

希望它会帮助你。

这篇关于转换一个VB code到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆