C basics
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

C# Basics PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.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);


  • Login