怎样把 VB.net程序转化成C#程序?在线等!

jeall 2003-08-25 10:28:06
例如http://www.ouryh.net/file1/show.asp?id=710上的关于一个实现树形结构的文章例子
...全文
236 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeall 2003-08-25
  • 打赏
  • 举报
回复
特别感谢doose!
feilong215,doose给得网址是一个不错的工具!
feilong215 2003-08-25
  • 打赏
  • 举报
回复
For 循环
for (int i=0; i<3; i++) a(i) = "test";
vb语句
Dim I As Integer For I = 0 To 2 a(I) = "test" Next

While 循环
int i = 0; while (i<3) { Console.WriteLine(i.ToString()); i += 1; }
vb语句
Dim I As Integer I = 0 Do While I < 3 Console.WriteLine(I.ToString()) I = I + 1 Loop

字符串联
String s1; String s2 = "hello"; s2 += " world"; s1 = s2 + " !!!";
vb语句
Dim s1, s2 As String s2 = "hello" s2 &= " world" s1 = s2 & " !!!"

事件处理
void MyButton_Click(Object sender, EventArgs E) { ... }
vb语句
Sub MyButton_Click(Sender As Object, E As EventArgs) ... End Sub "Note that ByVal is now the default "for params in VB

物件
MyObject obj = (MyObject)Session["Some Value"]; IMyObject iObj = obj
vb语句
Dim bj As MyObject Dim iObj As IMyObject obj = Session("Some Value") iObj = CType(obj, IMyObject)

转化
int i = 3; String s = i.ToString(); double d = Double.Parse(s);
vb语句
Dim i As Integer Dim s As String Dim d As Double i = 3 s = i.ToString() d = CDbl(s) " See also CDbl(...), CStr(...), ...

类的继承
using System; namespace MySpace { public class Foo : Bar { int x; public Foo() { x = 4; } public void Add(int x) { this.x += x; } public int GetNum() { return x; } } } // csc /out:librarycs.dll /t:library library.cs
vb语句
Imports System Namespace MySpace Public Class Foo : Inherits Bar Dim x As Integer Public Sub New() MyBase.New() x = 4 End Sub Public Sub Add(x As Integer) Me.x = Me.x + x End Sub Public Function GetNum() As Integer Return x End Function End Class End Namespace " vbc /out:libraryvb.dll /t:library library.vb

类的定义
using System; public class ConsoleCS { public ConsoleCS() { Console.WriteLine("Object Created"); } public static void Main (String[] args) { Console.WriteLine("Hello World"); ConsoleCS ccs = new ConsoleCS(); } } // csc /out:consolecs.exe /t:exe console.cs
vb语句
Imports System Public Class ConsoleVB Public Sub New() MyBase.New() Console.WriteLine("Object Created") End Sub Public Shared Sub Main() Console.WriteLine("Hello World") Dim cvb As ConsoleVB cvb = New ConsoleVB() End Sub End Class " vbc /out:consolevb.exe /t:exe console.vb

标准模组
using System; public class Module { public static void Main (String[] args) { Console.WriteLine("Hello World"); } } // csc /out:consolecs.exe /t:exe console.cs
vb语句
Imports System Public Module ConsoleVB Public Sub Main() Console.WriteLine("Hello World") End Sub End Module " vbc /out:consolevb.exe /t:exe console.vb
feilong215 2003-08-25
  • 打赏
  • 举报
回复
C# 语法 VB 语法
变量声明
int x; String s; String s1, s2; Object o; Object obj = new Object(); public String name;
vb语句
Dim x As Integer Dim s As String Dim s1, s2 As String Dim o "Implicitly Object Dim obj As New Object() Public name As String

语句
Response.Write("foo");
vb语句
Response.Write("foo")

注释
// This is a comment /* This is a multi-line comment */ "
vb语句
This is a comment " This " is " a " multi-line " comment

访问索引属性

String s = Request.QueryString["Name"]; String value = Request.Cookies["key"];
vb语句
Dim s, value As String s = Request.QueryString("Name") value = Request.Cookies("Key").Value "Note that default non-indexed properties "must be explicitly named in VB

声明一个属性
public String name { get { ... return ...; } set { ... = value; } /div>
vb语句
Public Property Name As String Get ... Return ...; End Get Set ... = Value; End Set End Property

数组
String[] a = new String[3]; a[0] = "1"; a[1] = "2"; a[2] = "3"; String[][] a = new String[3][3]; a[0][0] = "1"; a[1][0] = "2"; a[2][0] = "3"; Dim a(3) As String a(0) = "1" a(1) = "2" a(2) = "3" Dim a(3,3) As String a(0,0) = "1" a(1,0) = "2" a(2,0) = "3" " Array of unspecified bounds (NA in C#) Dim a() As String a(0,0) = "1" a(1,0) = "2" a(2,0) = "3"
vb语句
Dim a(,) As String a(0,0) = "1" a(1,0) = "2" a(2,0) = "3"
初始化
String s = "Hello World"; int i = 1 double[] a = { 3.00, 4.00, 5.00 }; Dim s As String = "Hello World" Dim i As Integer = 1 Dim a() As Double = { 3.00, 4.00, 5.00 }

IF 语句
if (Request.QueryString != null) { ... }
vb语句
If Not (Request.QueryString = Null) ... End If

Case 语句
switch (FirstName) { case "John" : ... break; case "Paul" : ... break; case "Ringo" : ... break; }
vb语句
Select (FirstName) case "John" : ... case "Paul" : ... case "Ringo" : ... End Select
doose 2003-08-25
  • 打赏
  • 举报
回复
http://www.ellkay.com/ConvertVB2CSharp.htm

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧