c basics
Download
Skip this Video
Download Presentation
C# Basics

Loading in 2 Seconds...

play fullscreen
1 / 8

C Basics - PowerPoint PPT Presentation


  • 117 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'C Basics' - pascha


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
c basics

C# Basics

Variables, Loops, Decision Statements, etc

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

Variables Declarations
using variables
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
simple arrays
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();

looping statements
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
decision statements
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++

simple console output
Simple Console Output

System.Console.WriteLine

System.Console.Write

System.Consolue.WriteLine ("count = {0} and sum = {1}",

count, sum);

simple console input
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);

ad