Bài giảng C# 2010 - Chapter 1: Working with Variables Operators and Expression

-A Statement is a command that performs an action, you must add “;” the end of command

-Ex: Console.Write(“Hello C# ”);

-Comments use to explain for your Coding

How to write comments???

See next slide

 

pptx16 trang | Chuyên mục: Visual C# | Chia sẻ: dkS00TYs | Lượt xem: 2199 | Lượt tải: 1download
Tóm tắt nội dung Bài giảng C# 2010 - Chapter 1: Working with Variables Operators and Expression, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 13/05/2013 ‹#› Working with Variables, Operators and Expressions Statements -Comments Identifiers Variables Primitive Data Types Arithmetic Operators Implicitly Typed Local Variables Incrementing & Decrementing Variables 1 2 3 4 5 6 7 Statements -Comments 1 -A Statement is a command that performs an action, you must add “;” the end of command -Ex: Console.Write(“Hello C# ”); -Comments use to explain for your Coding How to write comments??? See next slide… //Comment 1 /* *Comment 2 */ /*Comment 3*/ /// ///Write Comment 4 /// /// /// private void func1(int a,float b) Identifiers 2 Identifiers are names use to identify the elements in program, ex: namespace, class, method… Syntax Rules: -Only use letter, digit, underscore -An identifier must start with a letter or an underscore -C# is a case –sensitive : nTest and ntest is different identifier abstract 	do	 	in 	protected 	true as	double 	int 	public 	try base 	else 	interface 	readonly 	typeof bool 	enum 	internal 	ref 	uint break 	event 	is 	return 	ulong byte 	explicit 	lock 	sbyte 	unchecked case 	extern 	long 	sealed 	unsafe catch 	false 	namespace 	short 	ushort char 	finally 	new 	sizeof 	using checked 	fixed 	null 	stackalloc 	virtual class 	float 	object 	static 	void const 	for 	operator 	string 	volatile continue 	foreach 	out 	struct 	while decimal 	goto 	override 	switch default 	if 	params 	this delegate 	implicit 	private 	throw dynamic 	join 	set from 	let 	value get 	orderby 	var group 	partial 	where into 	select 	yield Identifying Keywords - A variable is storage location that holds a value. It as a box in the Computer’s memory holding temporary information. -To easy coding: +Don’t start an identifier with underscore +Don’t different only by case ( nTest and ntest) +Start name with lower case +…. Variables 3 How to declare variables? Data_type NameVariable; int nNumberOfElement; string strFullName; float fValue=0,fResult;  Data Type Description Size(bits) Range Example int Whole numbers 32 –231 through 231 – 1 int nSize; long Whole numbers (bigger range) 64 –263 through 263 – 1 long lSize; float Floating-point numbers 32 ±1.5 × 1045 through ±3.4 × 1038 float fDelta; double Double-precision (more accurate) floating-point numbers 64 ±5.0 × 10−324 through ±1.7 × 10308 double dDelta; decimal Monetary values 128 28 significant figures decimal decKe; string Sequence of characters 16 bits per character Not applicable string strName; char Single character 16 0 through 216 – 1 char chrAns; bool Boolean 8 True or false bool bRet; Primitive Data Types 4 You should initialize value for variable int nSize=0; String strName=“”; Arithmetic Operators 5 + - * / % () int nPlusTwoNumber=113 + 114 The + is the operator 113 and 114 are the operands Not all operators are applicable to all data types Example: You will get compiler error with the statements: Console.WriteLine(“Tý” - “Tèo”); How to convert from String to Number Format ? int nValue=System.Int32.Parse("113"); double dValue = System.Double.Parse("3.5"); Datatype vName=System.DataTypeObject.Parse(“string”); Incrementing & Decrementing Variables 6 X++ Postfix increment ++X Prefix increment X-- Postfix decrement --X Prefix decrement Implicitly Typed Local Variables 7 var sAny; Error: Implicitly-typed local variables must be initialized var number1=1; var strAny=“tèo”; END 

File đính kèm:

  • pptxBài giảng C# 2010 - Chapter 1 Working with Variables Operators and Expression.pptx
Tài liệu liên quan