当前位置:
首页 > 编程开发 > Objective-C编程 >
-
c#&vb两种语言语法的简要介绍
1.变量声名
C# 语法
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
2语句
C#:
Response.Write("中文c#技术站");
VB:
Response.Write("中文c#技术站")
3.注释语句
//中文c#技术站
/*
欢迎访问
,
中文c#技术站
*/
VB:
'中文c#技术站
4.获得URL 传递的变量
C#:
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
5.声明属性
C#:
public String name {
get {
...
return ...;
}
set {
... = value;
}
}
VB:
Public Property Name As String
Get
...
Return ...;
End Get
Set
... = Value;
End Set
End Property
6.数组
C#
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";
VB:
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"
Dim a() As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"
Dim a(,) As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"
7变量初始化
C#:
String s = "Hello World";
int i = 1
double[] a = { 3.00, 4.00, 5.00 };
VB:
Dim s As String = "Hello World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 }
8;判断语句(If 语句)
if (Request.QueryString != null) {
...
}
VB:
If Not (Request.QueryString = Null)
...
End If
9.分支语句(case 语句)
C#:
switch (FirstName) {
case "John" :
...
break;
case "Paul" :
...
break;
case "Ringo" :
...
break;
}
VB:
Select (FirstName)
case "John" :
...
case "Paul" :
...
case "Ringo" :
...
End Select
10 For循环语句
C#
for (int i=0; i<3; i++)
a(i) = "test";
VB:
Dim I As Integer
For I = 0 To 2
a(I) = "test"
Next
11 While 循环
C#:
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
12 字符串连接
C#:
String s1;
String s2 = "hello";
s2 += " world";
s1 = s2 + " !!!";
VB:
Dim s1, s2 As String
s2 = "hello"
s2 &= " world"
s1 = s2 & " !!!"
声明事件
C#:
void MyButton_Click(Object sender,
EventArgs E) {
...
}
VB:
Sub MyButton_Click(Sender As Object,
E As EventArgs)
...
End Sub
13 声明Object
C#
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)
14 数据类型转换
C#
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)
15 类的声明和继承
C#:
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; }
}
}
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
16 声明类的主函数
C#:
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();
}
}
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
17 标准模块
C#
using System;
public class Module {
public static void Main (String[] args) {
Console.WriteLine("Hello World");
}
}
VB:
Imports System
Public Module ConsoleVB
Public Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
C# 语法
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
2语句
C#:
Response.Write("中文c#技术站");
VB:
Response.Write("中文c#技术站")
3.注释语句
//中文c#技术站
/*
欢迎访问
,
中文c#技术站
*/
VB:
'中文c#技术站
4.获得URL 传递的变量
C#:
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
5.声明属性
C#:
public String name {
get {
...
return ...;
}
set {
... = value;
}
}
VB:
Public Property Name As String
Get
...
Return ...;
End Get
Set
... = Value;
End Set
End Property
6.数组
C#
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";
VB:
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"
Dim a() As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"
Dim a(,) As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"
7变量初始化
C#:
String s = "Hello World";
int i = 1
double[] a = { 3.00, 4.00, 5.00 };
VB:
Dim s As String = "Hello World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 }
8;判断语句(If 语句)
if (Request.QueryString != null) {
...
}
VB:
If Not (Request.QueryString = Null)
...
End If
9.分支语句(case 语句)
C#:
switch (FirstName) {
case "John" :
...
break;
case "Paul" :
...
break;
case "Ringo" :
...
break;
}
VB:
Select (FirstName)
case "John" :
...
case "Paul" :
...
case "Ringo" :
...
End Select
10 For循环语句
C#
for (int i=0; i<3; i++)
a(i) = "test";
VB:
Dim I As Integer
For I = 0 To 2
a(I) = "test"
Next
11 While 循环
C#:
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
12 字符串连接
C#:
String s1;
String s2 = "hello";
s2 += " world";
s1 = s2 + " !!!";
VB:
Dim s1, s2 As String
s2 = "hello"
s2 &= " world"
s1 = s2 & " !!!"
声明事件
C#:
void MyButton_Click(Object sender,
EventArgs E) {
...
}
VB:
Sub MyButton_Click(Sender As Object,
E As EventArgs)
...
End Sub
13 声明Object
C#
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)
14 数据类型转换
C#
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)
15 类的声明和继承
C#:
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; }
}
}
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
16 声明类的主函数
C#:
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();
}
}
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
17 标准模块
C#
using System;
public class Module {
public static void Main (String[] args) {
Console.WriteLine("Hello World");
}
}
VB:
Imports System
Public Module ConsoleVB
Public Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
JavaScript判断两个数组相等的四类方法
js如何操作video标签
React实战--利用甘特图和看板,强化Paas平
【记录】正则替换的偏方
前端下载 Blob 类型整理
抽象语法树AST必知必会
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程