Presentation is loading. Please wait.

Presentation is loading. Please wait.

Variables, Loops, Decision Statements, etc

Similar presentations


Presentation on theme: "Variables, Loops, Decision Statements, etc"— Presentation transcript:

1 Variables, Loops, Decision Statements, etc
C# Basics Variables, Loops, Decision Statements, etc

2 Variables Declarations
byte - 0 to 255 char - 2 bytes bool sbyte to 127 short - 2 byte int ushort - 0 to 65,535 int - 4 bytes uint - 4 bytes positive float double decimal long ulong string

3 Using Variables C# is Strongly Typed
float x = 10.9f; double y = 15.3; y = x; // okay x = (float) y; // conversion required Variables must have Value before being used. Hence declarations usually include initialization

4 Simple Arrays int[] myArray1 = new int[5];
for (int i=0;i<10; i++) Console.Write ("{0} ",myarray[i]); Console.WriteLine();

5 Looping Statements Same as C++ Different from C++ while (count > 0)
process_list (count--); do process_list( ++count ); while (count < 10); for (int i=1; i<=10; i++) Different from C++ while (count)// illegal C# unless count is bool

6 Decision Statements Almost Just Like C++ if (count >= 10) {
dostuff(); domorestuff(); } else ... switch (choice) { case 'Y': //must be empty case 'y': do_yes_stuff(); break; default: ...

7 Simple Console Output System.Console.WriteLine System.Console.Write
System.Consolue.WriteLine ("count = {0} and sum = {1}", count, sum);

8 Simple Console Input string inputline; char charvalue; int intvalue;
Console.Write ("Enter a string: "); inputline = Console.ReadLine(); Console.WriteLine("You just entered \"{0}\"",inputline); Console.Write ("Enter a character: "); charvalue = (char) Console.Read(); Console.WriteLine("You just entered \"{0}\"", charvalue); Console.ReadLine(); Console.Write ("Enter an integer: "); intvalue = Convert.ToInt32(inputline); Console.WriteLine("You just entered \"{0}\"", intvalue);


Download ppt "Variables, Loops, Decision Statements, etc"

Similar presentations


Ads by Google