Namespaces - PowerPoint PPT Presentation

About This Presentation
Title:

Namespaces

Description:

Compile and execute sequence. Typing. C# is a strongly 'typed' language ... Must know how big number will get. Data Types. Short (16 bit integer) Char (16 bit ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 15
Provided by: winston4
Category:

less

Transcript and Presenter's Notes

Title: Namespaces


1
Chapter 2
2
Chapter 2
  • Namespaces
  • Input and Output
  • List of some classes in System, Math etc
  • Compile and execute sequence

3
Typing
  • C is a strongly typed language
  • Most formal languages are (C, Cobol, Java)
  • Cannot mix numbers and characters
  • Must know how big number will get

4
Data Types
  • Short (16 bit integer)
  • Char (16 bit character)
  • Float (32 bit floating point number)
  • Boolean

5
Helpful Table
6
More on Data Types
  • Numeric
  • Integer (short, long, byte)
  • Floating point (for decimal fractions)
  • Decimal (with M suffix for money) 96 bits
  • Double (includes decimal places)
  • Character or String
  • Any character that has to appear
  • Boolean
  • Represents logical values (TRUE OR FALSE)

7
Numeric
  • Integer
  • Short(16) , long (32 bits), or byte (8bits)
  • Literals when you use a value in the program
  • Double (the default type)
  • Up to 15 decimal digits
  • Decimal
  • Up to 28 digits
  • Floating Point
  • Used to describe numbers with decimals
  • Use double to ensure full representation

8
Character
  • Char
  • One character within single quotes (x)
  • String
  • String
  • Many characters (a sentence)

9
Boolean
  • Bool data stores logical result (true or false)

10
Conversion
  • Sometimes programmer needs special variable
  • Two types in C Implicit and Explicit
  • Compiler protects user from unsafe choice
  • Casting converts inline float pi(float) 3.14
  • Default is double for Fl Pt literals
  • Casting overrides the double and allows cast

11
Program Style
  • We listed some // comments earlier
  • We also should have 4 sections in every program
  • // declare section (where you assign variables
    etc)
  • // input section (accept user input)
  • // computations (where you do calculations)
  • // display results
  • IN THAT ORDER

12
  • using System
  • namespace WTprog1
  • // wt
  • // program 1
  • // due date" 1/31/05
  • class Class1
  • static void Main(string args)
  • // declare section
  • // input section
  • // computation section
  • // display section
  • // end Main
  • //end class
  • // end namespace

13
Variables
  • To assign a value to an integer
  • int age
  • age 5
  • int tells the compiler that an integer follows
  • age is the case-sensitive variable name
  • 5 is the value that will be stored in age
  • If you had a statement to display the value,
  • Console.WriteLine(age is age)
  • Console.WriteLine(Age is 0, age)

14
Variables Contd
  • To assign a character value to a variable
  • char name d
  • Notice the single quotes?
  • In C each character occupies 16 bits, so that
    even Japanese etc can fit
  • You use string to input a whole name
  • nameSmith

15
Printing
  • Your program
  • string name jones
  • string major IS
  • string yr 02
  • Console.WriteLine(My name is name)
  • Console.WriteLine(Major mj year yr)
  • Console.WriteLine(Major 0, Year 1,
    major, yr

16
Variables
  • To get the computer to read data
  • string name Console.ReadLine()
  • Then you can use name as needed
Write a Comment
User Comments (0)
About PowerShow.com