Anda di halaman 1dari 4

ADIGRAT UNIVERSITY

Department of Information Technology


(Summer Program)
RAD- Lab Exercise1

1. Console applications Vs Graphical User Interface(GUI) Applications


a) Console applications
A console application has no a user interface: There are no list boxes, buttons,
windows, and so forth. Text input and output is handled through the standard console
(typically a command or DOS window on your computer).
The monitor is managed by an object named Console. This Console object has a method
WriteLine( )which takes a string(a set of characters) and writes it to the standard output.
The following C# program demonstrates a basic example of a console application:
using System;
namespace HelloWorld
{
classHelloWorld
{
staticvoid Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

Rewrite the above program in Visual Studio by creating a new project named HelloWorld and
run it to see its result.
Exercise 1.1
Write a C# program console application that should print the following output:
Rapid Application Development for
Summer III IT

Page1

Conditional Statements
The following examples of C# programs illustrate the different variants of the if condition.
Please rewrite all the examples on Visual Studio by creating new project for each and run them
to see their results.
Example 1: if statement
using System;
namespace CheckValueProgram
{
class CheckValue
{
static void Main(string[] args)
{
int number = 5;
if (number < 10)
{
Console.WriteLine("The number is less than 10");
}
}
}
}

Example 2: ifelse statement


using System;
namespace CheckNumberProgram
{
class CheckNumber
{
static void Main(string[] args)
{
int number = 5;
if (number < 10)
{
Console.WriteLine("The number is less than 10");
}
else
{
Console.WriteLine("The number is greater than 10");
}
}
}
}

Page2

Example 3: ifelse if statement


using System;
namespace CheckNumberProgram
{
class CheckNumber
{
static void Main(string[] args)
{
int number = 12;
if (number > 0 && number < 5)
{
Console.WriteLine("The number is
}
else if (number > 5 && number < 10)
{
Console.WriteLine("The number is
}
else if (number > 10 && number < 15)
{
Console.WriteLine("The number is
}
else
{
Console.WriteLine("The number is
}
}
}
}

between 0 and 5");

between 5 and 10");

between 10 and 15");

greater than 15");

Example 4: Switch statement


using System;
namespace CheckNumberProgram
{
class CheckNumber
{
static void Main(string[] args)
{
int number = 3;
switch (number)
{
case 1:
Console.WriteLine("The
break;
case 2:
Console.WriteLine("The
break;
case 3:
Console.WriteLine("The
break;
case 4:
Console.WriteLine("The
break;
case 5:

number is 1");

number is 2");

number is 3");

number is 4");

Page3

Console.WriteLine("The number is 5");


break;
default:
Console.WriteLine("The number not known");
break;
}
}
}
}

Page4

Anda mungkin juga menyukai