C# basics - { dostuff(); domorestuff(); } else ... switch...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
C# Basics Variables, Loops, Decision Statements, etc
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables Declarations byte - 0 to 255 char - 2 bytes bool sbyte - -128 to 127 short - 2 byte int ushort - 0 to 65,535 int - 4 bytes uint - 4 bytes positive float double decimal long ulong string
Background image of page 2
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
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple Arrays int[] myArray1 = new int[5]; int[] myArray2 = {1, 2, 3, 4, 5}; for (int i=0;i<10; i++) Console.Write ("{0} ",myarray[i]); Console.WriteLine();
Background image of page 4
Looping Statements Same as 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Decision Statements if (count >= 10)
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { dostuff(); domorestuff(); } else ... switch (choice) { case 'Y': //must be empty case 'y': do_yes_stuff(); break; default: ... Almost Just Like C++ Simple Console Output System.Console.WriteLine System.Console.Write System.Consolue.WriteLine (&quot;count = {0} and sum = {1}&quot;, count, sum); Simple Console Input string inputline; char charvalue; int intvalue; Console.Write (&quot;Enter a string: &quot;); inputline = Console. ReadLine (); Console.WriteLine(&quot;You just entered \&quot;{0}\&quot;&quot;,inputline); Console.Write (&quot;Enter a character: &quot;); charvalue = (char) Console. Read (); Console.WriteLine(&quot;You just entered \&quot;{0}\&quot;&quot;, charvalue); Console. ReadLine (); Console.Write (&quot;Enter an integer: &quot;); inputline = Console.ReadLine(); intvalue = Convert.ToInt32(inputline) ; Console.WriteLine(&quot;You just entered \&quot;{0}\&quot;&quot;, intvalue);...
View Full Document

Page1 / 8

C# basics - { dostuff(); domorestuff(); } else ... switch...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online