Management_企业管理类英文版 PPT课件.ppt_第1页
Management_企业管理类英文版 PPT课件.ppt_第2页
Management_企业管理类英文版 PPT课件.ppt_第3页
Management_企业管理类英文版 PPT课件.ppt_第4页
Management_企业管理类英文版 PPT课件.ppt_第5页
已阅读5页,还剩68页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

chap 2 introduction to c# (78),1,chapter 2 introduction to c # programming,chap 2 introduction to c# (78),2,outline,2.1 basic operation & introduction 2.2 a simple c program 2.3 variables concepts 2.4 data types 2.5 arithmetic in c 2.6 math class 2.7 examples 2.8 homeworks,basic operation,solution(方案) may have a lot of projects (專案) project(專案) may have one application create a new project (xx.cs) editing a source file compile and link the files in a project into executable file run the executable file,debug mode,execution,output,chap 2 introduction to c# (78),11,introduction,c# 是一種優雅、簡單、具型別安全、物件導向的程式語言,允許企業的程式設計師建立各種應用程式。 c# 語言是改良過後的 c 和 c+ 語言。 c# 提供通用 api 樣式的存取權限:.net framework、com、automation 和 c 樣式的 api 支援 unsafe 模式,在這種模式下,您便可以使用指標來操作未受記憶體回收控制的記憶體。,chap 2 introduction to c# (78),12,a simple program 1: welcome.cs,namespace mynamespace using system; / namespace declaration class welcomecss / program start class / main begins program execution. public static void main() / write to console console.writeline(“welcome to the c#!“); ,chap 2 introduction to c# (78),13,statement,console.writeline(.) statement “welcome to the c#!“ is output on the console screen. console is a class in the system namespace. writeline(.) is a method in the console class. use the “.“, dot, operator to separate subordinate program elements. system.console.writeline(.). “namespace.class.method“ system.console.writeline(.). ( with no namespace declaration),chap 2 introduction to c# (78),14,system,console,writeline(),namespace,class,method,system.console.writeline() using system; console.writeline(),chap 2 introduction to c# (78),15,console.writeline,console.writeline(“values: 0, 1“, val1, val2); 0 指向第一個後跟引數,而 1 指向第二個後跟引數,以此類推。 在輸出結果傳送到主控台 (console) 之前,每一個替代符號都會取代成其相對應引數的格式化數值。,chap 2 introduction to c# (78),16,comments,single line comments: marked with “/“. they are valid until the end-of-line. multiple lines with a comment, begin with “/*“ and end with “*/“. everything in between is part of the comment. comments are not considered when your program is compiled. they are there to document what your program does in plain english (or the native language you speak with every day).,chap 2 introduction to c# (78),17,a simple program 2,using system; / namespace declaration class interactivewelcome / program start class public static void main() console.write(“what is your name?: “); console.write(“hello, 0! “, console.readline(); console.writeline(“welcome to the c#!“); ,chap 2 introduction to c# (78),18,statements,console.write(.) statement writes to the console and stops on the same line, but the console.writeline(.) goes to the next line after writing to the console. console.readline(): causes the program to wait for user input at the console, followed by a return or enter.,chap 2 introduction to c# (78),19,system,console,write (),namespace,class,method,writeline(),readline(),chap 2 introduction to c# (78),20,statements,the return value from this method replaces the “0“ parameter of the formatted string and is written to the console string name = console.readline(); console.write(“hello, 0! “, name);,chap 2 introduction to c# (78),21,a simple program 2,using system; / namespace declaration class interactivewelcome / program start class public static void main() string name; console.write(“what is your name?: “); name = console.readline(); console.write(“hello, 0! “, name); console.writeline(“welcome to the c#!“); ,chap 2 introduction to c# (78),22,variable,correspond to locations in the computers memory. every variable has a name, a type, a size and a value. whenever a new value is placed into a variable, it replaces (and destroys) previous value reading variables from memory does not change them name a variable with letters, digits and underline the first character should be a letter or a underline.,chap 2 introduction to c# (78),23,variable,case sensitive; readability no reserved word can be used to name a variable. example correct: total, sum, no_of_moves, _sysflag, ab87y6 incorrect: income$tax, tax rate, 9people, float,chap 2 introduction to c# (78),24,c# data types(簡單型別 ),boolean type three numeric types integrals floating point decimal,chap 2 introduction to c# (78),25,represents logical values literal values are true and false cannot use 1 and 0 as boolean values no standard conversion between other types and bool,boolean type,chap 2 introduction to c# (78),26,example,using system; class booleans public static void main() bool content = true; bool nocontent = false; console.writeline(“it is 0 that c# station provides c# programming language content.“, content); console.writeline(“the statement above is not 0.“, nocontent); ,chap 2 introduction to c# (78),27,integral types,integral types are well suited for those operations involving whole number calculations. the char type is the exception, representing a single unicode character.,chap 2 introduction to c# (78),28,integrals type,chap 2 introduction to c# (78),29,integer data type,decimal: 123, octal: 07 prefix code: 0 example: 017 (15), -023(-19), 0177(127) hexadecimal: 09,a,b,c,d,e,f prefix code: 0x or 0x example: ox17 (26), -0x9f(-175), 0x5eb (1515),chap 2 introduction to c# (78),30,integral literals,integer literals can be expressed as decimal or hexadecimal u or u: uint or ulong l or l: long or ulong ul or ul: ulong,123 / decimal 0x7b / hexadecimal 123u / unsigned 123ul / unsigned long 123l / long,chap 2 introduction to c# (78),31,character,represents a unicode character a character enclosed with a pair of single quote() literals a / simple character u0041 / unicode x0041 / unsigned short hexadecimal n / escape sequence character,chap 2 introduction to c# (78),32,predefined types char,escape sequence characters (partial list),chap 2 introduction to c# (78),33,floating point and decimal types,floating point types are used when you need to perform operations requiring fractional representations.,chap 2 introduction to c# (78),34,floating point and decimal types,the decimal type may be your best choice for financial calculations. decimal 型別很適合用在會因不接受浮點數表示方式而產生進位錯誤的計算過程中。常見範例包括金融計算作業,例如,稅務計算和匯率轉換。decimal 型別可以提供28位數的有效位數,chap 2 introduction to c# (78),35,floating point and decimal types,chap 2 introduction to c# (78),36,floating point data type,real number example 123.45 -0.956 1.47e7 ( 1.47*107) +1.496e-18 (1.496*10-18) double double precision floating point,chap 2 introduction to c# (78),37,real literals,f or f: float d or d: double m or m: decimal,123f / float 123d / double 123.456m / decimal 1.23e2f / float 12.3e1m / decimal,chap 2 introduction to c# (78),38,variable declaration - 1,all variables should be declared before they are used. format datatype variablename integer datatype: int x; long y; short a,b,c;,chap 2 introduction to c# (78),39,variable declaration - 2,real declaration float x; double y,z; character declaration char c;,chap 2 introduction to c# (78),40,constant declaration,to declare a constant: data value can only be set once const type varname; const double pay_rate = 150.50;,chap 2 introduction to c# (78),41,arithmetic,arithmetic calculations are used in most programs use * for multiplication and / for division integer division truncates remainder 7 / 5 evaluates to 1 modulus operator returns the remainder 7 % 5 evaluates to 2,chap 2 introduction to c# (78),42,arithmetic,operator precedence some arithmetic operators act before others (i.e., multiplication before addition) use parenthesis when needed example: find the average of three variables a, b and c do not use: a + b + c / 3 use: (a + b + c ) / 3,chap 2 introduction to c# (78),43,precedence: top to down,chap 2 introduction to c# (78),44,modulo %,modulo is the remainder operator % returns the remainder the division of 2 numbers in .net this works in all kinds of numbers not only integers 9 % 2 1 15 % 4 3 15 % 5 0 2.5 % 2 0.5 precedence rules in a mixed expression * / % are evaluated before + - 2 + 3 * 4 14 16 8 / 4 * 2 12 always use () to make it clear (2 + 3) * 4 20 (16 8) / (4 * 2) 1,chap 2 introduction to c# (78),45,association,left association means that operations are evaluated from left to right. right association means all operations occur from right to left, such as assignment operators where everything to the right is evaluated before the result is placed into the variable on the left.,chap 2 introduction to c# (78),46,arithmetic,arithmetic operators,chap 2 introduction to c# (78),47,arithmetic,rules of operator precedence,chap 2 introduction to c# (78),48,increment operator,format +variablename; variablename+; is equal to operation is different to the postfix operation. variablename=variablename+1; if this operation is located in a expression, the prefix the prefix operation will be executed before the whole operation, while the postfix operation will be executed after the whole operation.,chap 2 introduction to c# (78),49,increment operator,example a = 10; b = 5 + +a; is equal to a = 10; a = a+1; b = 5 + a;,example a = 10; b = 5 + a+; is equal to a = 10; b = 5 + a; a = a+1;,chap 2 introduction to c# (78),50,decrement operator,format -variablename; variablename-; is equal to variablename=variablename-1; if this operation is located in a expression, the prefix operation is different to the postfix operation. the prefix operation will be executed before the whole operation, while the postfix operation will be executed after the whole operation.,chap 2 introduction to c# (78),51,type conversion,often times variables of one type must be converted to another type keyboard input into applications are initially captured as string. we may need to convert this to int, float, decimal, etc. “1” is a string of the integer 1 there are 3 ways to convert from one type to another implicit conversion explicit conversion system.convert,chap 2 introduction to c# (78),52,type conversion,implicit conversion automatic conversion completed by the .net framework works when converting from a smaller data size to a larger data size e.g. from int float, float double converting from a subclass to a more general class (more on this later),chap 2 introduction to c# (78),53,automatic data type conversion,long,float,int,short,byte,ushort,high level,low level,decimal,sbyte,uint,double,ulong,char,chap 2 introduction to c# (78),54,type conversion examples,implicit conversion,know what you are converting from and to! beware of data loss!,chap 2 introduction to c# (78),55,type conversion,explicit conversion (casting) works anyway you want it (but may execute with error!) used for .net built-in data types and custom types truncates all decimals e.g. convert 1.66 to int 1,chap 2 introduction to c# (78),56,explicit conversion table,chap 2 introduction to c# (78),57,type conversion examples,explicit conversion,know what you are converting from and to! beware of data loss!,chap 2 introduction to c# (78),58,type conversion,system.convert converts from one data type to another used only for .net built in data types can convert to unrelated data types string int string double,chap 2 introduction to c# (78),59,common system.convert methods,chap 2 introduction to c# (78),60,type conversion examples,system.convert,know what you are converting from and to! beware of data loss!,chap 2 introduction to c# (78),61,system.math,提供三角函數、對數函數和其他一般數學函數的常數和靜態方法。,公用欄位,chap 2 introduction to c# (78),62,chap 2 introduction to c# (78),63,the math class,examples of operations include math.round math.abs math.cos math.floor math.log math.min math.pow math.sqrt,chap 2 introduction to c# (78),64,example,console.writeline( “square root of 900 is 0“, math.sqrt( 900.0 ) ); calls method sqrt, which returns the square root of its argument all math functions return data type double arguments may be constants, variables, or expressions,chap 2 introduction to c# (78),65,basic program,using system; / namespace declaration class program1 / program start class / main begins program execution. public static void main() variable declaration; output some message; input some data; calculation; output results; ,chap 2 introduction

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论