国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

vb.net和c#語法比較

2024-07-10 13:00:38
字體:
供稿:網(wǎng)友
國內(nèi)最大的酷站演示中心!
由于一些人對(duì)vb.net和c#選擇方面存在一些困惑,其實(shí)只是語法習(xí)慣問題,我把它們的語法列出來比較一下,大家有個(gè)感性認(rèn)識(shí)。



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#技術(shù)站"); 

vb: 

response.write("中文c#技術(shù)站") 



3.注釋語句 

//中文c#技術(shù)站

/* 

歡迎訪問

, 

中文c#技術(shù)站

*/ 



vb: 

'中文c#技術(shù)站



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.數(shù)組 

c# 

string[] a = new string[3]; 

a[0] = "1"; 

a[1] = "2"; 

a[2] = "3"; 

//二維數(shù)組 

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循環(huán)語句 

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 循環(huán) 

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 數(shù)據(jù)類型轉(zhuǎn)換 

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 聲明類的主函數(shù) 

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 標(biāo)準(zhǔn)模塊 

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 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平阳县| 民勤县| 黄骅市| 华安县| 景宁| 新郑市| 涟水县| 措勤县| 镇沅| 梓潼县| 嘉义市| 乐亭县| 辰溪县| 内江市| 察雅县| 通辽市| 淮南市| 东至县| 桂平市| 安陆市| 仁布县| 惠来县| 全南县| 综艺| 伊金霍洛旗| 桐梓县| 栾川县| 泗水县| 大厂| 台中县| 灵台县| 日照市| 那坡县| 北京市| 恩平市| 红安县| 绿春县| 宝兴县| 渝中区| 油尖旺区| 临湘市|