请将VB.net代码转换为C# [英] Please Convert VB.net Code to C#
本文介绍了请将VB.net代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
Any one please convert this code in C# Code
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Text
Namespace LNTSystems.CommonControls
Partial Class MsgBox
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private content As String
Public Sub alert(ByVal msg As String)
Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
sMsg = msg.Replace("""", "'")
Dim sb As StringBuilder = New StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert( """ + sMsg + """ );")
sb.Append("</script>")
content = sb.ToString
End Sub
Public Sub alert(ByVal msg As String, ByVal Redirect As String)
Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
sMsg = msg.Replace("""", "'")
Dim sb As StringBuilder = New StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert( """ + sMsg + """ );")
sb.Append("window.navigate( """ + Redirect + """ );")
sb.Append("</script>")
content = sb.ToString
End Sub
Public Sub confirm(ByVal msg As String, ByVal hiddenfield_name As String)
Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
sMsg = msg.Replace("""", "'")
Dim sb As StringBuilder = New StringBuilder
sb.Append("<INPUT type=hidden value='0' name='" + hiddenfield_name + "'>")
sb.Append("<script language='javascript'>")
sb.Append(" if(confirm( """ + sMsg + """ ))")
sb.Append(" { ")
sb.Append("document.forms[0]." + hiddenfield_name + ".value='1';" + "document.forms[0].submit(); }")
sb.Append(" else { ")
sb.Append("document.forms[0]." + hiddenfield_name + ".value='0'; }")
sb.Append("</script>")
content = sb.ToString
End Sub
Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
output.Write(Me.content)
End Sub
End Class
End Namespace
我正在跟踪此链接.但是在上面的代码中,hwenever"Chr"在那里,它表明某些错误不包含Chr的定义.
http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ]
i''m following this link . but in above code hwenever "Chr" is there in that it show some error doesn''t contain a definition for Chr.
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
推荐答案
尝试使用此代码翻译器:
http://www.carlosag.net/tools/codetranslator/ [
Try this code translator:
http://www.carlosag.net/tools/codetranslator/[^]
这是一个工具: ^ ]由于转换工具有时代码有误,因此我不确定转换后是否一定可以,您可以尝试一下.祝您好运!
Here is a tool: http://www.tangiblesoftwaresolutions.com/[^]Since conversion tool sometimes have wrong code, so I am not sure it must be all right after converting, you can try. Good luck!
从VB.NET转换为C#的代码转换器并非100%,您需要手动更改一些代码,就像您发现Microsoft.VisualBasic.Chr(10)
作为其中之一他们
这些链接向您展示了如何在C#中执行相同的操作
什么是chr()函数的C#等价物? [ Asc和Chr的C#等价 [
Code translators aren''t 100% in converting from VB.NET to C#, you will need to manually change some code like you have found theMicrosoft.VisualBasic.Chr(10)
as one of them
these links show you how to do the same in C#
What is the C# equivalent of the chr() function?[^]
C# equivilent for Asc and Chr[^]
but here is a simple example conversion
Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
致
To
Char newLine = (char)10;
string sMsg = msg.Replace(newLine, @"\n");
这篇关于请将VB.net代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文