C l namespace Hello class Hello Class static

  • Slides: 42
Download presentation

โปรแกรมภาษา C# l พจารณาโปรแกรมตอไปน namespace Hello { class Hello. Class { static void Main

โปรแกรมภาษา C# l พจารณาโปรแกรมตอไปน namespace Hello { class Hello. Class { static void Main () { System. Console. Write. Line("Hello World!"); System. Console. Read. Line(); } } }

คำสง (Statement( namespace Hello. W { class Hello. WClass { static void Main ()

คำสง (Statement( namespace Hello. W { class Hello. WClass { static void Main () { System. Console. Write. Line("Hello World!"); System. Console. Read. Line(); } } } method 1 method 2 Statement#1 Statement#2 : Class Namespace

ลำดบการคำนวณ Rules( 1. 2. 3. 4. (Precedence () *, / , % +, –

ลำดบการคำนวณ Rules( 1. 2. 3. 4. (Precedence () *, / , % +, – ซายไปขวา int Width, Height; Width = 10*5+(16 * 12)/5; Height = (16+5)+20%2;

ตวอยางโปรแกรม : Read. Line l โปรแกรมดานลางจะใหผใชปอนชอแล ะกลาวคำทกทาย using System; class Hello. You { static

ตวอยางโปรแกรม : Read. Line l โปรแกรมดานลางจะใหผใชปอนชอแล ะกลาวคำทกทาย using System; class Hello. You { static void Main() { string name; Console. Write("What is your name: "); name = Console. Read. Line(); Console. Write. Line("Hello, {0}", name); } }

ตวอยาง : คำนวณพนทสเหลยม using System; class Area. Calculation { static void Main() { int

ตวอยาง : คำนวณพนทสเหลยม using System; class Area. Calculation { static void Main() { int width, height, area; string input; Console. Write("Enter width: "); Obtaining "width" input = Console. Read. Line(); width = int. Parse(input); Console. Write("Enter height: "); Obtaining "height" input = Console. Read. Line(); height = int. Parse(input); area = width * height; Console. Write. Line("Area = {0}x{1} = {2}", width, height, area); } } width height area = width x height