1 / 8

C# Basics

C# Basics. Variables, Loops, Decision Statements, etc. 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. Variables Declarations. Using Variables.

pascha
Download Presentation

C# Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 Variables Declarations

  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]; int[] myArray2 = {1, 2, 3, 4, 5}; for (int i=0;i<10; i++) Console.Write ("{0} ",myarray[i]); Console.WriteLine();

  5. 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

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

  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: "); inputline = Console.ReadLine(); intvalue = Convert.ToInt32(inputline); Console.WriteLine("You just entered \"{0}\"", intvalue);

More Related