Please help translating VB.NET code to C#

M

Michael Rodriguez

Can anyone please translate the following VB.NET code to C# for me?

Imports System.Net
Public Class NoKeepAliveHttpWebRequestCreate
Implements IWebRequestCreate

Overridable Overloads Function Create(ByVal uri As Uri) As WebRequest
Implements IWebRequestCreate.Create
Dim wr As HttpWebRequest
Dim s As String

' strip the 'x' from the beginning of the url so the normal Http protocol is
used
s = uri.ToString.Substring(1)
wr = WebRequest.Create(New Uri(s))
wr.KeepAlive = False

Return wr
End Function
End Class


Thanks!

Mike Rodriguez
 
N

Nicholas Paldino [.NET/C# MVP]

Michael,

It would look something like this:

using System.Net;

public class NoKeepAliveHttpWebRequestCreate : IWebRequestCreate
{
WebRequest IWebRequestCreate.Create(Uri uri)
{
string s = uri.ToString().Substring(1);
wr = WebRequest.Create(new Uri(s));
wr.KeepAlive = false;
return wr;
}
}

Hope this helps.
 
J

Jimi

I think the following is more accurate (using the Instant C# vb.net to
c# converter - www.instantcsharp.com):

using System.Net;
public class NoKeepAliveHttpWebRequestCreate : IWebRequestCreate

{
//INSTANT C# NOTE: This method implements an interface method
//ORIGINAL LINE: Overridable Function Create(ByVal uri As Uri) As
WebRequest Implements IWebRequestCreate.Create
public virtual WebRequest Create(Uri uri)
{
HttpWebRequest wr = null;
string s = "";

// strip the 'x' from the beginning of the url so the normal Http
protocol is used
s = uri.ToString().Substring(1);
wr = WebRequest.Create(new Uri(s));
wr.KeepAlive = false;

return wr;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top