DELPHI与C#语法比较.doc

上传人:工**** 文档编号:551763337 上传时间:2022-09-08 格式:DOC 页数:13 大小:139KB
返回 下载 相关 举报
DELPHI与C#语法比较.doc_第1页
第1页 / 共13页
DELPHI与C#语法比较.doc_第2页
第2页 / 共13页
DELPHI与C#语法比较.doc_第3页
第3页 / 共13页
DELPHI与C#语法比较.doc_第4页
第4页 / 共13页
DELPHI与C#语法比较.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《DELPHI与C#语法比较.doc》由会员分享,可在线阅读,更多相关《DELPHI与C#语法比较.doc(13页珍藏版)》请在金锄头文库上搜索。

1、窗体顶端窗体底端您查询的关键词是:delphic# 。如果打开速度慢,可以尝试快速版;如果想保存快照,可以添加到搜藏。(百度和网页http:/ | 留言交流 | 首页 我的图书馆 主题阅读 精彩目录 精品文苑 Tags 会员浏览 好书推荐 DELPHI与C#语法比较(转载)kenwang 收录于2007-04-05 阅读数:公众公开原文来源 DELPHI and C# ComparisonDELPHI7与C#语法比较编制:黄焕尧参考:VB.net and C# Comparison日期:2005-5-30. Comments 注释Data Types数据类 Constants 常量Enumer

2、ations 枚举Operators 运算Choices 选择语句Loops 循环语句Arrays 数组Functions 函数Exception Handling 异常处理Namespaces 命名空间Classes / Interfaces Constructors / Destructors 构造/释构Objects 对象Structs 结构Properties 属性Delegates / Events Console I/O File I/O DELPHIC#Comments注释/ Single line onlyMultiple line (*Multiple line *)/ Si

3、ngle line/* Multiple line */ XML comments on single line/* XML comments on multiple lines */Data Types 数据类型Value Types 简单类型BooleanByteChar (example: Ac)Word, Integer, Int64Real ,Single, Double,Real48,Extended,Comp,CurrencyDecimalTdate,TDateTimeReference TypesObjectString(ShortString,AnsiString,WideS

4、tring)Set, array, record, file,class,class reference,interfacepointer, procedural, variantvar x:Integer; WriteLine(x); /Prints System.Int32 WriteLine(Ingeger); / Prints Integer/Type conversionvar numDecimal:Single = 3.5 ;var numInt:Integer;numInt :=Integer(numDecimal) / set to 4 (Bankers rounding) t

5、he decimal)Value Typesboolbyte, sbytechar (example: A)short, ushort, int, uint, long, ulongfloat,doubledecimalDateTime (not a built-in C#type)Reference Typesobjectstringint x;Console.WriteLine(x.GetType();/ Prints System.Int32Console.WriteLine(typeof(int); / Prints System.Int32 / Type conversion dou

6、ble numDecimal = 3.5; int numInt = (int) numDecimal; / set to3 (truncates decimal)Constants常量ConstMAX_STUDENTS:Integer = 25;const int MAX_STUDENTS = 25;Enumerations枚举Type Taction1=(Start, Stop, Rewind, Forward);$M+Type Status=(Flunk = 50, Pass = 70, Excel = 90); $M-var a:Taction1 = Stop; If a Start

7、Then WriteLn(ord(a); / Prints1 WriteLine(Ord(Pass); / Prints 70 WriteLine(GetEnumName(TypeInfo(Status),Ord(Pass);/ Prints Pass ShowEnum(Pass); /outputs 70GetEnumValue(GetEnumName(TypeInfo(Status),Pass);/70enum Action Start, Stop, Rewind, Forward;enum Status Flunk = 50, Pass = 70, Excel = 90;Action a

8、 = Action.Stop;if (a != Action.Start) Console.WriteLine(a + is + (int) a);/ Prints Stop is 1Console.WriteLine(Status.Pass); / Prints PassOperators运算符Comparison 比较= = in asArithmetic 算述述运算+ - * / divMod (integer division) (raise to a power) 阶乘Assignment 赋值分配:= Inc() Dec() shl shr Bitwise 位运算andxor or

9、 not shl shr/Logicaland xor ornot/String Concatenation+Comparison= = !=Arithmetic+ - * /% (mod)/ (integer division if both operands are ints)Math.Pow(x, y)Assignment= += -= *= /= %= &= |= = = + -Bitwise& | Logical& | !Note: & and|perform short-circuit logical evaluationsString Concatenation+Choices

10、判断greeting := IfThen (age 20, Whats up?, Hello);If language = DELPHI Then langType := hymnlan;/If x 100 Then begin x := x*5 ; y :=x* 2;end;/or to break up any long single command use _If(whenYouHaveAReally LinesThen UseTheUnderscore(charToBreakItUp);If x 5 Then x :=x* y Else Ifx = 5 Then x :=x+ y El

11、se If x 10 Then x :=x- y Else x :=x/ y ;Case colorof / 不能为字符串类型 pink, red: r :=r+ 1; blue: b :=b+1; green: g :=g+ 1; Else Inc(other); End; greeting = age 5) x *= y; else if (x = 5) x += y; else if (x 10) x -= y; else x /= y;switch (color) / Must be integer or string case pink: case red: r+; break; /

12、 break is mandatory; no fall-through case blue: b+; break; case green: g+; break; default: other+; break; / break necessary on default Loops 循环Pre-test Loops: While c 10 do Inc(c) ;EndFor c = 2 To 10 do WriteLn(IntToStr(c); For c = 10 DownTo 2 do WriteLn(IntToStr(c); repeat Inc(c); Until c = 10;/ Array or collection loopingcount names:array of String = (Fred, Sue, Barney) For i:=low(name) to High(name) do WriteLn(namei); DELPHI8开始支持 for each 语法Pre-test Loops: / no u

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号