Lab 1 Introduction To Visual Programming
Lab 1 Introduction To Visual Programming
Any C# application can be written with a simple text editor (such as Notepad) as long
as the Framework Class Libraries (FCL) are present. Normally, however, it is much
simpler to program and manage C# applications using the Visual Studio Integrated
Development Environment (IDE), which contains:
The Start Page is the first wide area that appears when Microsoft Visual Studio comes up. The
left section displays a list of recently used projects under Recent Projects. At any time, to display
the Start Page:
You can click the Start Page label in the top section of the Code Editor
On the main menu, you can click View Start Page
The Solution Explorer is a window that displays a list of the files that
make up a project. To access the Solution Explorer:
The C# console applications display on a black window referred to as the DOS prompt or DOS
window. To start such an application, you can use Microsoft Visual Studio as described below.
To assist you with writing code, if you use Microsoft Visual C# Express or Microsoft Visual Studio
Professional, it includes a text editor referred to as the Code Editor. If you create your project as a
Console Application, a default file would be created and you can customize it.
If you start your program as an empty project, you must explicitly add a file to it. To do that:
OR
In the Solution Explorer, right-click the name of the project, position the mouse on Add,
and click New Item...
Any of these actions would display the Add New Item dialog box. From there, in the
middle list, click Code File. Accept the name or change it. When you click OK, a blank
document would display. In the same way, you can add as many files as you need for
your project.
// Namespace declaration
using System;
The namespace declaration, using System; indicates that you are referencing the System
namespace. Namespaces contain groups of code that can be called upon by C# programs. With
the using System; declaration, you are telling your program that it can reference the code in the
System namespace.
The class declaration, class WelcomeCS, contains the data and method definitions that your
program uses to execute. A class is one of a few different types of elements your program can
use to describe objects. This particular class has no data, but it does have one method. This
method defines the behavior of this class (or what it is capable of doing).
The first thing you should be aware of is that C# is case-sensitive. The word "Main" is not the
same as its lower case spelling, "main". They are different identifiers.A static
modifierproceeds the word Main, meaning that this method works in this specific class only,
class WelcomeCS
{
static void Main(string[] args)
{
\n to\n C#\
}
}
The IDE displays a design-time view of the visible portion, if any, of the object being
designed.
A Designer view of a formobject appears by default in a new project.
The form will be a window at run time.
The IDE provides an editor for building the actual code for the class or classes that make
up your new project.
Pre-existing (library) code is not visible here.
Choose View Code icon in Solution Explorer or click Code tab in Designer Window.
MessageBoxButton.OK
MessageBoxButton.OKCANCEL
MessageBoxButton.YESNO
MessageBoxButton.YESNOCANCEL
MessageBoxButton.RETRYCANCEL
MessageBoxButton.ABORTRETRYIGNORE
Exercise1.1
Create a console application to calculate the factorial of the number using for loop. For example
if n=5 then factorial of 5 will be 1*2*3*4*5= 120.
Exercise 1.2
Create a console application, ask the user to input a string, save the string in a variable and then
check whether the string consists of any vowels (a, e, i, o, u). Display the total number of vowels
present in the string.
Exercise 1.3
Create a Console application in which you have to input a number from the user and then output
the respective grade the student got using if-else statement with the help of the table given
below:
A--------------------- (87-100)
B+------------------- (80-86)
B--------------------- (72-80)
C+------------------- (66-71)
C--------------------- (61-65)
Exercise1.4
Create a Windows Form application, calculate the sum of the series and display the series and its
sum in a messagebox.
Se
Exercise 1.5
Create a Windows Form application and then print the table of 2 in a MessageBox.
2x1=2
2x2=4
2x3=6
.
.
.
2x10=20