Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 st Semester 2005 1 Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.

Similar presentations


Presentation on theme: "1 st Semester 2005 1 Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering."— Presentation transcript:

1 1 st Semester 2005 1 Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang aphirak.j@ku.ac.th http://www.cpe.ku.ac.th/~aphirak Computer Engineering Department Kasetsart University, Bangkok THAILAND

2 1 st Semester 2005 2 Outline  C# Overview  Variable and Constant  Expression  Statement

3 1 st Semester 2005 3 C# Program Overview  C# is an object-oriented programming language. class.  Everything must be in some class.  A program is a set of class declarations. แดง ขาว ด่าง โฮ่ง สุนัข class C# Overview

4 1 st Semester 2005 4 Very simple C# program example Starting Point C# Overview

5 1 st Semester 2005 5 Simple C# program structure Your Class Name Your declaration part Your statements Your Namespace Name C# Overview

6 1 st Semester 2005 6 C# Keywords Example 1 2 3 Any keywords? C# Overview

7 1 st Semester 2005 7 More C# Keywords Example C# Overview

8 1 st Semester 2005 8 What is Objects? In computer languages “an object is called class” Object = Properties + Methods C# Overview

9 1 st Semester 2005 9 Example: Class declaration  Class Car class car { }  Class Human class human { { static void main() } } C# Overview

10 1 st Semester 2005 10 What is Namespace? Section of code specific name “Section of code that is identified by a specific name” Namespace example1 class Human class Car C# Overview Namespace example2 class Car

11 1 st Semester 2005 11 Example: namespace declaration  Namespace example1 namespace example1 { }  Namespace example2 + Class car namespace example2 { class car { } } C# Overview

12 1 st Semester 2005 12 Naming Guidelines  Letters, digits, underscores(_)  First character  letter  Can be long (63 char)  Reserved words (keywords) are not allowed *** Case Sensitive *** Example KU56 ≠ kU56 ≠ku56 KU56 ≠ kU56 ≠ ku56 C# Overview

13 1 st Semester 2005 13 Built-in Namespace: System Console Console class can be used for Displaying Displaying information on the screenSystem.Console.Write(”HelloWorld!”);System.Console.WriteLine(”HelloWorld!”); Retrieving Retrieving information from the user String ch; ch = System.Console.Readline(); C# Overview

14 1 st Semester 2005 14 Example: Console class C# Overview

15 1 st Semester 2005 15 Summary C# Program Overview  Namespace Class  Main() C# Overview

16 1 st Semester 2005 16 Practice: Try it by yourself  Declare the following class/namespace in C# syntax Class Movie Class HelloWorld Namespace KU65  Class Man  Class Woman C# Overview

17 1 st Semester 2005 17 Reference Problem  Calculate AREA of Rectangle!!! Width High AREA = Width x High C# Overview

18 1 st Semester 2005 18 Level1: Reference Problem C# Overview

19 1 st Semester 2005 19 Short break – 8 Minutes

20 1 st Semester 2005 20 Outline  C# Overview  Variable and Constant  Expression  Statement

21 1 st Semester 2005 21 Basic uses Declaration Part  Variable  Constant Variable & Constant

22 1 st Semester 2005 22 What is Variable? Variables are used to store “data.” “They must be declared before used” Variable & Constant

23 1 st Semester 2005 23 C# Declaration Location Declaration Part Here Variable & Constant

24 1 st Semester 2005 24 C# Variable Declaration  Syntax: ;  Example:  We can also assign its initial value. E.g., int radius; double area; int a,b,c; bool isokay; int k = 200; bool done = false; Variable & Constant

25 1 st Semester 2005 25 C# Basic Data Type  int Integer ( -2147483648 to 2147483647)  double Floating-point ( )  bool Boolean values, true and false  char a Unicode character (’A’ ’B’)  string string of Unicode characters (”StarsIII”) Variable & Constant

26 1 st Semester 2005 26 Basic uses Declaration Part  Variable  Constant Variable & Constant

27 1 st Semester 2005 27 C# Constant Declaration  Syntax: const = ;  Example: const int radius = 15; const double area=1.5; const bool isokay=true; const string movie=”StarWarIII”; Variable & Constant

28 1 st Semester 2005 28 Example: Variable Declaration Variable & Constant

29 1 st Semester 2005 29 Level2: Reference Problem Variable & Constant

30 1 st Semester 2005 30 Short break – 5 Minutes

31 1 st Semester 2005 31 Outline  C# Overview  Variable and Constant  Expression  Statement

32 1 st Semester 2005 32 Expression in C#  Arithmetic Expression  Boolean ExpressionExpression

33 1 st Semester 2005 33 Arithmetic Expression  Operators + - * / % (remainder after division)  Example 11 + 5  16 11 / 2  5.5 11 % 2  1 5.0 % 2.2  0.6Expression

34 1 st Semester 2005 34 Precedence rules for Arithmetic Operators 1.( ) parentheses 2.*, /, % 3.+ – 4.If equal precedence, left to right Example int Width,High; Width=10*5+(16 * 12)/5; High= (16+5)+20%2;

35 1 st Semester 2005 35 Expression in C#  Arithmetic Expression  Boolean ExpressionExpression

36 1 st Semester 2005 36 Boolean Expression  Operators Comparison =  Equal = !=  Not equal != <  Less < >  Greater > <=  Less than or equal to <= >=  Greater than or equal to >= Boolean &&  And && ||  Or ||Expression

37 1 st Semester 2005 37 Short break – 5 Minutes

38 1 st Semester 2005 38 Outline  C# Overview  Variable and Constant  Expression  Statement

39 1 st Semester 2005 39 C# Statement LocationStatementsHereStatement

40 1 st Semester 2005 40 C# Statement Types  Assignment Statement  Input Statement  Output StatementStatement

41 1 st Semester 2005 41 Assignment Statement "put"  To "put" a value in the memory space allocated to a variable equal sign (=)  Use the equal sign (=) when making assignments.  Syntax: = ; = ; int Width,High; Width=10;High=5; int Width = 10; int High = 5; Statement

42 1 st Semester 2005 42 Example: Assignment StatementStatement

43 1 st Semester 2005 43 C# Statement Types  Assignment Statement  Input Statement  Output StatementStatement

44 1 st Semester 2005 44 Input Statement  Console.ReadLine()  Return string Use to get the input from user  Convert string to other data type int.Parse() Convert string to integer double.Parse() Convert string to double Example string yourname; yourname = Console.ReadLine(); Statement

45 1 st Semester 2005 45 Example: Input Statement Ex1: string myname; myname = Console.ReadLine(); Ex2: int Width,High; string temp1; temp1 = Console.ReadLine(); Width = int.Parse(temp1); temp1 = Console.ReadLine(); Width = int.Parse(temp1); Statement

46 1 st Semester 2005 46 Level3: Reference Problem Statement

47 1 st Semester 2005 47 C# Statement Types  Assignment Statement  Input Statement  Output StatementStatement

48 1 st Semester 2005 48 Output Statement  Console.WriteLine(VariableName)  Display variable value in some position of string  Output Formatting Example1 Console.WriteLine(”Hello {0}, {1}”, ps0, ps1); Example2 double salary=12000; Console.WriteLine("My salary is {0:f}.", salary); More information about formatting *http://msdn.microsoft.com/library/en-us/csref/html/vclrfFormattingNumericResultsTable.asp Statement

49 1 st Semester 2005 49 Level4: Reference Problem Statement

50 1 st Semester 2005 50 Summary  C# Overview  Variable and Constant  Expression  StatementSummary


Download ppt "1 st Semester 2005 1 Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering."

Similar presentations


Ads by Google