Вы находитесь на странице: 1из 33

chapter 2

Introduction to c# Application Click to edit Master subtitle style

9/30/12

objective

Write simple C# applications using code Write input/output statements. Declare and use data of various types. Store and retrieve data from memory. Use arithmetic operators. Determine the order in which operators are applied. Write decision-making statements. Use relational and equality operators.

9/30/12

simple c# APP

9/30/12

Hello world program


using System; public class Welcome { // Main method begins execution of C# application public static void Main( string[] args ) { Console.WriteLine( Hello C# World!" ); }
9/30/12 }

part of program

Comment Code Directive

9/30/12

demo

9/30/12

variable

9/30/12

variable in math

x=3+2
What is the meaning of x?

9/30/12

what is variable?

variable is a block of memory. is a way that programmer use to store information or data. is the information or data use by program

9/30/12

how to declare variable

syntax:

modifier+ data type+ variable name[+=+ initializer]+; Ex: public string x; public string x=c sharp; note: C sharp is case sensitive. ex: public <> Public <> pUblic <> puBlic
9/30/12

variable naming

not begin with number or symbol no space not the same as c sharp keyword

9/30/12

key word

9/30/12

stop and check


Why we need variable? to store data. to calculate to make decision

9/30/12

demo

9/30/12

data type

9/30/12

what is data type


Classification identifying one of various types of data like number, text, image etc.

9/30/12

primitive data type


Data type Byte Short int Long Float double Decimal Bool char string 9/30/12 Description Unsigned integer Signed integer Whole numbers Whole numbers (bigger range) Floating-point numbers Double-precision Monetary values True, false Single character series character Size (bits) 8 16 32 64 32 64 96 8 16 --

demo

9/30/12

arithmetic operator

9/30/12

9/30/12

stop and check

9/30/12

demo

9/30/12

arithmetic operator precedence

9/30/12

9/30/12

stop and check


what is the result of the 1*2/2*4+1/2? 1 4.5 2.5 0.75

9/30/12

demo

9/30/12

decision statement

9/30/12

how can we make decision?

if statement that allows an application to make a decision based on the value of a condition.

9/30/12

using if
if ( number1 == number2 ) //doing some thing

9/30/12

demo

9/30/12

relational and equal operator

9/30/12

9/30/12

demo

9/30/12

Вам также может понравиться