仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 734|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET编程:C#和VB.net语法对照图

[复制链接]
萌萌妈妈 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:34:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
归根到底,Java跨平台可以,但是要重新编写代码,否则还分什么J2EE/J2SE/J2ME呢!语法C#和VB.net的语法相差仍是对照年夜的.大概你会C#,大概你会VB.
将它们俩放在一同对照一下你就会很快读懂,并把握另外一门言语.
信任上面这张图会对你匡助很年夜.
Comments

VB.NET
  1. SinglelineonlyRemSinglelineonly
复制代码
C#
  1. //Singleline/*Multipleline*////XMLcommentsonsingleline/**XMLcommentsonmultiplelines*/
复制代码
DataTypes

VB.NET
  1. ValueTypesBooleanByteChar(example:"A")Short,Integer,LongSingle,DoubleDecimalDateReferenceTypesObjectStringDimxAsIntegerSystem.Console.WriteLine(x.GetType())System.Console.WriteLine(TypeName(x))TypeconversionDimdAsSingle=3.5DimiAsInteger=CType(d,Integer)i=CInt(d)i=Int(d)
复制代码
C#
  1. //ValueTypesboolbyte,sbytechar(example:A)short,ushort,int,uint,long,ulongfloat,doubledecimalDateTime//ReferenceTypesobjectstringintx;Console.WriteLine(x.GetType())Console.WriteLine(typeof(int))//Typeconversionfloatd=3.5;inti=(int)d
复制代码
Constants

VB.NET
  1. ConstMAX_AUTHORSAsInteger=25ReadOnlyMIN_RANKAsSingle=5.00
复制代码
C#
  1. constintMAX_AUTHORS=25;readonlyfloatMIN_RANKING=5.00;
复制代码
Enumerations

VB.NET
  1. EnumActionStartStopisareservedword[Stop]RewindForwardEndEnumEnumStatusFlunk=50Pass=70Excel=90EndEnumDimaAsAction=Action.StopIfaAction.StartThen_Prints"Stopis1"System.Console.WriteLine(a.ToString&"is"&a)Prints70System.Console.WriteLine(Status.Pass)PrintsPassSystem.Console.WriteLine(Status.Pass.ToString())
复制代码
C#
  1. enumAction{Start,Stop,Rewind,Forward};enumStatus{Flunk=50,Pass=70,Excel=90};Actiona=Action.Stop;if(a!=Action.Start)//Prints"Stopis1"System.Console.WriteLine(a+"is"+(int)a);//Prints70System.Console.WriteLine((int)Status.Pass);//PrintsPassSystem.Console.WriteLine(Status.Pass);
复制代码
Operators

VB.NET
  1. Comparison=<=>=Arithmetic+-*/Mod(integerdivision)^(raisetoapower)Assignment=+=-=*=/==^=<<=>>=&=BitwiseAndAndAlsoOrOrElseNot<>LogicalAndAndAlsoOrOrElseNotStringConcatenation&
复制代码
C#
  1. //Comparison==<=>=!=//Arithmetic+-*/%(mod)/(integerdivisionifbothoperandsareints)Math.Pow(x,y)//Assignment=+=-=*=/=%=&=|=^=<<=>>=++--//Bitwise&|^~<>//Logical&&||!//StringConcatenation+
复制代码
Choices

VB.NET
  1. greeting=IIf(age<20,"Whatsup?","Hello")Onelinedoesntrequire"EndIf",no"Else"Iflanguage="VB.NET"ThenlangType="verbose"Use:toputtwocommandsonsamelineIfx100Andy<5Thenx*=5:y*=2PreferredIfx100Andy<5Thenx*=5y*=2EndIfortobreakupanylongsinglecommanduse_IfhenYouHaveAReally<longLineAnd_itNeedsToBeBrokenInto2>LinesThen_UseTheUnderscore(charToBreakItUp)Ifx>5Thenx*=yElseIfx=5Thenx+=yElseIfx<10Thenx-=yElsex/=yEndIfMustbeaprimitivedatatypeSelectCasecolorCase"black","red"r+=1Case"blue"b+=1Case"green"g+=1CaseElseother+=1EndSelect
复制代码
C#
  1. greeting=age<20?"Whatsup?":"Hello";if(x!=100&&y<5){//Multiplestatementsmustbeenclosedin{}x*=5;y*=2;}if(x>5)x*=y;elseif(x==5)x+=y;elseif(x<10)x-=y;elsex/=y;//Mustbeintegerorstringswitch(color){case"black":case"red":r++;break;case"blue"break;case"green":g++;break;default:other++;break;}
复制代码
Loops

VB.NET
  1. Pre-testLoops:Whilec<10c+=1EndWhileDoUntilc=10c+=1LoopPost-testLoop:DoWhilec<10c+=1LoopForc=2To10Step2System.Console.WriteLine(c)NextArrayorcollectionloopingDimnamesAsString()={"Steven","SuOk","Sarah"}ForEachsAsStringInnamesSystem.Console.WriteLine(s)Next
复制代码
C#
  1. //Pre-testLoops:while(i<10)i++;for(i=2;i<=10;i+=2)System.Console.WriteLine(i);//Post-testLoop:doi++;while(i<10);//Arrayorcollectionloopingstring[]names={"Steven","SuOk","Sarah"};foreach(stringsinnames)System.Console.WriteLine(s);
复制代码
Arrays

VB.NET
  1. Dimnums()AsInteger={1,2,3}ForiAsInteger=0Tonums.Length-1Console.WriteLine(nums(i))Next4istheindexofthelastelement,soitholds5elementsDimnames(4)AsStringnames(0)="Steven"ThrowsSystem.IndexOutOfRangeExceptionnames(5)="Sarah"Resizethearray,keepingtheexistingvalues(Preserveisoptional)ReDimPreservenames(6)DimtwoD(rows-1,cols-1)AsSingletwoD(2,0)=4.5Dimjagged()()AsInteger={_NewInteger(4){},NewInteger(1){},NewInteger(2){}}jagged(0)(4)=5
复制代码
C#
  1. int[]nums={1,2,3};for(inti=0;i<nums.Length;i++)Console.WriteLine(nums[i]);//5isthesizeofthearraystring[]names=newstring[5];names[0]="Steven";//ThrowsSystem.IndexOutOfRangeExceptionnames[5]="Sarah"//C#cantdynamicallyresizeanarray.//Justcopyintonewarray.string[]names2=newstring[7];//ornames.CopyTo(names2,0);Array.Copy(names,names2,names.Length);float[,]twoD=newfloat[rows,cols];twoD[2,0]=4.5;int[][]jagged=newint[3][]{newint[5],newint[2],newint[3]};jagged[0][4]=5;
复制代码
Functions

VB.NET
  1. Passbyvalue(in,default),reference(in/out),andreference(out)SubTestFunc(ByValxAsInteger,ByRefyAsInteger,ByRefzAsInteger)x+=1y+=1z=5EndSubcsettozerobydefaultDima=1,b=1,cAsIntegerTestFunc(a,b,c)System.Console.WriteLine("{0}{1}{2}",a,b,c)125AcceptvariablenumberofargumentsFunctionSum(ByValParamArraynumsAsInteger())AsIntegerSum=0ForEachiAsIntegerInnumsSum+=iNextEndFunctionOruseaReturnstatementlikeC#DimtotalAsInteger=Sum(4,3,2,1)returns10OptionalparametersmustbelistedlastandmusthaveadefaultvalueSubSayHello(ByValnameAsString,OptionalByValprefixAsString="")System.Console.WriteLine("Greetings,"&prefix&""&name)EndSubSayHello("Steven","Dr.")SayHello("SuOk")
复制代码
C#
  1. //Passbyvalue(in,default),reference//(in/out),andreference(out)voidTestFunc(intx,refinty,outintz){x++;y++;z=5;}inta=1,b=1,c;//cdoesntneedinitializingTestFunc(a,refb,outc);System.Console.WriteLine("{0}{1}{2}",a,b,c);//125//AcceptvariablenumberofargumentsintSum(paramsint[]nums){intsum=0;foreach(intiinnums)sum+=i;returnsum;}inttotal=Sum(4,3,2,1);//returns10/*C#doesntsupportoptionalarguments/parameters.Justcreatetwodifferentversionsofthesamefunction.*/voidSayHello(stringname,stringprefix){System.Console.WriteLine("Greetings,"
  2. +prefix+""+name);}voidSayHello(stringname){SayHello(name,"");}
复制代码
ExceptionHandling

VB.NET
  1. DeprecatedunstructurederrorhandlingOnErrorGoToMyErrorHandler...MyErrorHandler:System.Console.WriteLine(Err.Description)DimexAsNewException("Somethinghasreallygonewrong.")ThrowexTryy=0x=10/yCatchexAsExceptionWheny=0ArgumentandWhenisoptionalSystem.Console.WriteLine(ex.Message)FinallyDoSomething()EndTry
复制代码
C#




  1. Exceptionup=newException("Somethingisreallywrong.");throwup;//hahatry{y=0;x=10/y;}catch(Exceptionex){//Argumentisoptional,no"When"keywordConsole.WriteLine(ex.Message);}finally{//Dosomething}
复制代码
Namespaces

VB.NET
  1. NamespaceASPAlliance.DotNet.Community...EndNamespaceorNamespaceASPAllianceNamespaceDotNetNamespaceCommunity...EndNamespaceEndNamespaceEndNamespaceImportsASPAlliance.DotNet.Community
复制代码
C#
  1. namespaceASPAlliance.DotNet.Community{...}//ornamespaceASPAlliance{namespaceDotNet{namespaceCommunity{...}}}usingASPAlliance.DotNet.Community;
复制代码
Classes/Interfaces

VB.NET
  1. AccessibilitykeywordsPublicPrivateFriendProtectedProtectedFriendSharedInheritanceClassArticlesInheritsAuthors...EndClassInterfacedefinitionInterfaceIArticle...EndInterfaceExtendinganinterfaceInterfaceIArticleInheritsIAuthor...EndInterfaceInterfaceimplementation</span>ClassPublicationDateImplements</strong>IArticle,IRating...EndClass
复制代码
C#
  1. //Accessibilitykeywordspublicprivateinternalprotectedprotectedinternalstatic//InheritanceclassArticles:Authors{...}//InterfacedefinitioninterfaceIArticle{...}//ExtendinganinterfaceinterfaceIArticle:IAuthor{...}//InterfaceimplementationclassPublicationDate:IArticle,IRating{...}
复制代码
Constructors/Destructors

VB.NET
  1. ClassTopAuthorPrivate_topAuthorAsIntegerPublicSubNew()_topAuthor=0EndSubPublicSubNew(ByValtopAuthorAsInteger)Me._topAuthor=topAuthorEndSubProtectedOverridesSubFinalize()DesctructorcodetofreeunmanagedresourcesMyBase.Finalize()EndSubEndClass
复制代码
C#
  1. classTopAuthor{privateint_topAuthor;publicTopAuthor(){_topAuthor=0;}publicTopAuthor(inttopAuthor){this._topAuthor=topAuthor}~TopAuthor(){//Destructorcodetofreeunmanagedresources.//ImplicitlycreatesaFinalizemethod}}
复制代码
Objects

VB.NET
  1. DimauthorAsTopAuthor=NewTopAuthorWithauthor.Name="Steven".AuthorRanking=3EndWithauthor.Rank("Scott")author.Demote()CallingSharedmethodorTopAuthor.Rank()Dimauthor2AsTopAuthor=authorBothrefertosameobjectauthor2.Name="Joe"System.Console.WriteLine(author2.Name)PrintsJoeauthor=NothingFreetheobjectIfauthorIsNothingThen_author=NewTopAuthorDimobjAsObject=NewTopAuthorIfTypeOfobjIsTopAuthorThen_System.Console.WriteLine("IsaTopAuthorobject.")
复制代码
C#
  1. TopAuthorauthor=newTopAuthor();//No"With"constructauthor.Name="Steven";author.AuthorRanking=3;author.Rank("Scott");TopAuthor.Demote()//CallingstaticmethodTopAuthorauthor2=author//Bothrefertosameobjectauthor2.Name="Joe";System.Console.WriteLine(author2.Name)//PrintsJoeauthor=null//Freetheobjectif(author==null)author=newTopAuthor();Objectobj=newTopAuthor();if(objisTopAuthor)SystConsole.WriteLine("IsaTopAuthorobject.");
复制代码
Structs

VB.NET
  1. StructureAuthorRecordPublicnameAsStringPublicrankAsSinglePublicSubNew(ByValnameAsString,ByValrankAsSingle)Me.name=nameMe.rank=rankEndSubEndStructureDimauthorAsAuthorRecord=NewAuthorRecord("Steven",8.8)Dimauthor2AsAuthorRecord=authorauthor2.name="Scott"System.Console.WriteLine(author.name)PrintsStevenSystem.Console.WriteLine(author2.name)PrintsScott
复制代码
C#
  1. structAuthorRecord{publicstringname;publicfloatrank;publicAuthorRecord(stringname,floatrank){this.name=name;this.rank=rank;}}AuthorRecordauthor=newAuthorRecord("Steven",8.8);AuthorRecordauthor2=authorauthor.name="Scott";SystemConsole.WriteLine(author.name);//PrintsStevenSystem.Console.WriteLine(author2.name);//PrintsScott
复制代码
Properties

VB.NET
  1. Private_sizeAsIntegerPublicPropertySize()AsIntegerGetReturn_sizeEndGetSet(ByValValueAsInteger)IfValue<0Then_size=0Else_size=ValueEndIfEndSetEndPropertyfoo.Size+=1
复制代码
C#
  1. privateint_size;publicintSize{get{return_size;}set{if(value<0)_size=0;else_size=value;}}foo.Size++;
复制代码
Delegates/Events

VB.NET
  1. DelegateSubMsgArrivedEventHandler(ByValmessageAsString)EventMsgArrivedEventAsMsgArrivedEventHandlerortodefineaneventwhichdeclaresadelegateimplicitlyEventMsgArrivedEvent(ByValmessageAsString)AddHandlerMsgArrivedEvent,AddressOfMy_MsgArrivedCallbackWontthrowanexceptionifobjisNothingRaiseEventMsgArrivedEvent("Testmessage")RemoveHandlerMsgArrivedEvent,AddressOfMy_MsgArrivedCallbackImportsSystem.Windows.FormsWithEventscantbeusedonlocalvariableDimWithEventsMyButtonAsButtonMyButton=NewButtonPrivateSubMyButton_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesMyButton.ClickMessageBox.Show(Me,"Buttonwasclicked","Info",_MessageBoxButtons.OK,MessageBoxIcon.Information)EndSub
复制代码
C#
  1. delegatevoidMsgArrivedEventHandler(stringmessage);eventMsgArrivedEventHandlerMsgArrivedEvent;//DelegatesmustbeusedwitheventsinC#MsgArrivedEvent+=newMsgArrivedEventHandler(My_MsgArrivedEventCallback);//ThrowsexceptionifobjisnullMsgArrivedEvent("Testmessage");MsgArrivedEvent-=newMsgArrivedEventHandler(My_MsgArrivedEventCallback);usingSystem.Windows.Forms;ButtonMyButton=newButton();MyButton.Click+=newSystem.EventHandler(MyButton_Click);privatevoidMyButton_Click(objectsender,
  2. System.EventArgse){MessageBox.Show(this,"Buttonwasclicked","Info",MessageBoxButtons.OK,MessageBoxIcon.Information);}
复制代码
ConsoleI/O

VB.NET
  1. SpecialcharacterconstantsvbCrLf,vbCr,vbLf,vbNewLinevbNullStringvbTabvbBackvbFormFeedvbVerticalTab""Chr(65)ReturnsASystem.Console.Write("Whatsyourname?")DimnameAsString=System.Console.ReadLine()System.Console.Write("Howoldareyou?")DimageAsInteger=Val(System.Console.ReadLine())System.Console.WriteLine("{0}is{1}yearsold.",name,age)orSystem.Console.WriteLine(name&"is"&age&"yearsold.")DimcAsIntegerc=System.Console.Read()ReadsinglecharSystem.Console.WriteLine(c)Prints65ifuserenters"A"
复制代码
C#
  1. //Escapesequencesn,rtConvert.ToChar(65)
  2. //ReturnsA-equivalenttoChr(num)inVB//or(char)65System.Console.Write("Whatsyourname?");stringname=SYstem.Console.ReadLine();System.Console.Write("Howoldareyou?");intage=Convert.ToInt32(System.Console.ReadLine());System.Console.WriteLine("{0}is{1}yearsold.",
  3. name,age);//orSystem.Console.WriteLine(name+"is"+
  4. age+"yearsold.");intc=System.Console.Read();//ReadsinglecharSystem.Console.WriteLine(c);
  5. //Prints65ifuserenters"A"
复制代码
FileI/O

VB.NET
  1. ImportsSystem.IOWriteouttotextfileDimwriterAsStreamWriter=File.CreateText("c:myfile.txt")writer.WriteLine("Outtofile.")writer.Close()ReadalllinesfromtextfileDimreaderAsStreamReader=File.OpenText("c:myfile.txt")DimlineAsString=reader.ReadLine()WhileNotlineIsNothingConsole.WriteLine(line)line=reader.ReadLine()EndWhilereader.Close()WriteouttobinaryfileDimstrAsString="Textdata"DimnumAsInteger=123DimbinWriterAsNewBinaryWriter(File.OpenWrite("c:myfile.dat"))binWriter.Write(str)binWriter.Write(num)binWriter.Close()ReadfrombinaryfileDimbinReaderAsNewBinaryReader(File.OpenRead("c:myfile.dat"))str=binReader.ReadString()num=binReader.ReadInt32()binReader.Close()
复制代码
C#
  1. usingSystem.IO;//WriteouttotextfileStreamWriterwriter=File.CreateText("c:myfile.txt");writer.WriteLine("Outtofile.");writer.Close();//ReadalllinesfromtextfileStreamReaderreader=File.OpenText("c:myfile.txt");stringline=reader.ReadLine();while(line!=null){Console.WriteLine(line);line=reader.ReadLine();}reader.Close();//Writeouttobinaryfilestringstr="Textdata";intnum=123;BinaryWriterbinWriter=newBinaryWriter(File.OpenWrite("c:myfile.dat"));binWriter.Write(str);binWriter.Write(num);binWriter.Close();//ReadfrombinaryfileBinaryReaderbinReader=newBinaryReader(File.OpenRead("c:myfile.dat"));str=binReader.ReadString();num=binReader.ReadInt32();binReader.Close();
复制代码
那做企业软件是不是最好用J2EE?
第二个灵魂 该用户已被删除
沙发
发表于 2015-1-18 11:59:15 | 只看该作者
它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。
再见西城 该用户已被删除
板凳
发表于 2015-1-21 21:01:28 | 只看该作者
平台无关性是PHP的最大优点,但是在优点的背后,还是有一些小小的缺点的。如果在PHP中不使用ODBC,而用其自带的数据库函数(这样的效率要比使用ODBC高)来连接数据库的话,使用不同的数据库,PHP的函数名不能统一。这样,使得程序的移植变得有些麻烦。不过,作为目前应用最为广泛的一种后台语言,PHP的优点还是异常明显的。
金色的骷髅 该用户已被删除
地板
发表于 2015-1-30 22:20:25 | 只看该作者
大哥拜托,Java在95年就出来了,微软垄断个妹啊,服务器市场微软完全是后后来者,当年都是Unix的市场,现在被WindowsServer和Linux抢下大片,包括数据库也一样。
简单生活 该用户已被删除
5#
发表于 2015-2-6 16:20:43 | 只看该作者
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象。
不帅 该用户已被删除
6#
发表于 2015-2-17 05:04:59 | 只看该作者
ASP在执行的时候,是由IIS调用程序引擎,解释执行嵌在HTML中的ASP代码,最终将结果和原来的HTML一同送往客户端。
若相依 该用户已被删除
7#
发表于 2015-3-5 16:23:05 | 只看该作者
Servlet却在响应第一个请求的时候被载入,一旦Servlet被载入,便处于已执行状态。对于以后其他用户的请求,它并不打开进程,而是打开一个线程(Thread),将结果发送给客户。由于线程与线程之间可以通过生成自己的父线程(ParentThread)来实现资源共享,这样就减轻了服务器的负担,所以,JavaServlet可以用来做大规模的应用服务。
兰色精灵 该用户已被删除
8#
发表于 2015-3-12 10:39:06 | 只看该作者
主流网站开发语言之CGI:CGI就是公共网关接口(CommonGatewayInterface)的缩写。它是最早被用来建立动态网站的后台技术。这种技术可以使用各种语言来编写后台程序,例如C,C++,Java,Pascal等。
海妖 该用户已被删除
9#
发表于 2015-3-19 20:43:03 | 只看该作者
使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行,用户端的浏览器不需要提供任何别的支持,这样大提高了用户与服务器之间的交互的速度。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-24 00:47

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表