






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Clear() clear a range of elements. Copy() copy a section of an array to another. Reverse() reverse order of array. Sort() sort a one dim array. Length().
Typology: Summaries
1 / 11
This page cannot be seen from the preview
Don't miss anything!







slide 2 gaius
slide 3 gaius
slide 4 gaius
do statementsequences; while (expr);
gaius
while (expr) statementsequences;
gaius
char ch;
ch = f.ReadChar (); // the ½ component while (ch != ’z’) { ... // the N component ch = f.ReadChar (); }
slide 7 gaius
for ( initialisers ; expression; iterators ) statementsequences;
slide 8 gaius
for (int i = 1; i <= 12; i++) Console.WriteLine ("8 x {0} = {1}", i, 8*i);
for (int i = 1; i <= 12; i++) { Console.WriteLine ("8 x {0} = {1}", i, 8*i); }
gaius
public static void delay () { Thread.Sleep (250); // sleep for 250 milliseconds }
gaius
slide 15 gaius
using System; using System.Threading;
public class test { public static void delay () { Thread.Sleep (250); // sleep for 250 milliseconds }
public static void Main () { char ch; ConsoleKeyInfo name;
do { name = Console.ReadKey (); Console.WriteLine ("you typed {0}", name.KeyChar); delay (); } while (name.KeyChar != ’x’); } }
slide 16 gaius
gaius
gaius
public static void Main () { char ch = ’a’; // variable is assigned as not ’x’
Console.Clear (); // clears screen do { if (GetChar (ref ch)) Console.WriteLine ("you typed {0}", ch); else { Console.WriteLine ("move monster"); delay (); } } while (ch != ’x’); }
slide 19 gaius
slide 20 gaius
public static bool GetChar (ref char ch) { if (Console.KeyAvailable) { ConsoleKeyInfo k = Console.ReadKey (); ch = k.KeyChar; return true; } return false; }
gaius
int[] myArray;
myArray = new int[5];
gaius
int[] myPrimes1 = new int[5] {1, 2, 3, 5, 7}; int[] myPrimes2 = {1, 2, 3, 5, 7};
int[] myArray2 = new int[10];
for (int i = 0; i < myArray2.Length; i++) { myArray2[i] = 42; }
slide 27 gaius
int total = 0;
foreach (int v in myPrimes2) { total += v; }
slide 28 gaius
double [,]matrix = new double[3,3]; /* indices 0-2, 0-2 *
for (int i = 0; i < 3 ; i++) { for (int j = 0; j < 3; j++) { matrix[i, j] = 0.0; } }
gaius
double [,]matrix = new double[3,3]; /* indices 0-2, 0-2 */
for (int i = 0; i < matrix.GetLength (0); i++) { for (int j = 0; j < matrix.GetLength (1); j++) { matrix[i, j] = 0.0; } }
gaius
public static void Main () { if (completed_all ()) Console.WriteLine ("well done, you have completed
all levels and your score was {0}", score); else Console.WriteLine ("you died with a score of {0}", s }
slide 31 gaius
slide 32 gaius
#..#######.##.##....p....##.###.###....### ##.#######....##.........##.....###.###### #..........##.#############.###.........## #.######.####...................#######.## #..#####.####.#############.###.#######.## ##.#####.####......###......###..........# #........#########.###.#################.# #.################.###.#################.# #m.......................................# ##########################################
gaius
public static bool gathered_food () { return food == 0; }
gaius
public static bool GetCharTimeout (ref char ch) { for (int i = current_delay; i > 0; i -= 40) { if (GetChar (ref ch)) return true; else Thread.Sleep (40); // 40 millisecs } return false; }
slide 39 gaius
public static bool GetChar (ref char ch) { if (Console.KeyAvailable) { ConsoleKeyInfo k = Console.ReadKey ();
if (k.Key == ConsoleKey.Escape) Environment.Exit(0);
ch = k.KeyChar; return true; } return false; }
slide 40 gaius
slide 41 gaius