



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




2
3
4
r Program specifications (optional) //========================================================== // // File: HelloWorld.cs CS112 Demo // // Author: Zhong Shao Email: [email protected] // // Classes: HelloWorld // -------------------- // This program prints the string "Hello World!” // //========================================================== r Library imports (optional) using System; r Class and namespace definitions
class HelloWorld { static void Main(string[] args) { Console.WriteLine(“Hello World!”); } }
5
r Program specifications (optional) //========================================================== // // File: HelloWorld.cs CS112 Demo // // Author: Zhong Shao Email: [email protected] // // Classes: HelloWorld // -------------------- // This program shows a message box. // //========================================================== r Library imports (optional) using System; using System.Windows.Forms; r Class and namespace definitions class HelloWorld { static void Main(string[] args) { MessageBox.Show(“Hello World!”); } }
6
7
8
9
10
11
12
19
20
21
m byte, sbyte, short, ushort, int, uint, long,ulong
m float, double
m decimal
m bool
m char
m string
m object
22
Range
0 - 255 -128 - 127 -32,768 - 32767 0 - 65537 -2,147,483,648 – 2,147,483, 0 – 4,294,967, -9× 1018 to 9× 1018 0 – 1.8× 1019
±1.0× 10 -28; ±7.9× 1028 with 28-29 significant digits
±1.5× 10 -45; ±3.4× 1038 with 7 significant digits ±5.0× 10 -324; ±1.7× 10308 with 15-16 significant digits Question: you need a variable to represent world population. Which type do you use?
Type
byte sbyte short ushort int uint long ulong
decimal
float double
Storage
8 bits 8 bits 16 bits 16 bits 32 bits 32 bits 64 bits 64 bits
128 bits
32 bits 64 bits
23
24
25
m Uses sixteen bits per character, allowing for 65,536 unique characters m It is an international character set, containing symbols and characters from many languages m Code chart can be found at: http://www.unicode.org/charts/
26
Escape sequence Description \n Newline. Position the screen cursor to the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. Any characters output after the carriage return overwrite the previous characters output on that line. \’ Used to print a single quote \ Backslash. Used to print a backslash character. " (^) Double quote. Used to print a double quote ( " ) character.
27
28
29
m Used to get a value from the user input m Example
string myString = Console.ReadLine();
m Int32.Parse()
m Double.Parse() m Single.Parse()
30
System.Console.WriteLine(“{0} {1}.”, iAmVar0, iAmVar1);
float price = 2.5f; System.Console.WriteLine(“Price = {0:C}.”, price);
Price = $2.50.
http://msdn.microsoft.com/library/en-us/csref/html/vclrfFormattingNumericResultsTable.asp