Lab 01
Lab 01
CSC412-Visual Programming
1
Lab 01
Introduction to Visual Studio
Objective:
This lab will give you an introduction to Visual Studio environment and developing first Console based
application using C# language.
Activity Outcomes:
The activities provide hands - on practice with the following topics
• Installing Visual Studio
• Understanding Visual Studio environment
• Creating Console based application using Visual Studio
• Developing first console based application using C# language
• Understanding structure of console based application
1) Useful Concepts
Visual Studio is a complete set of development tools for building ASP.NET Web applications, XML Web
Services, desktop applications, and mobile applications. Visual Basic, Visual C#, and Visual C++ all use
the same integrated development environment (IDE), which enables tool sharing and eases the creation of
mixed-language solutions. In addition, these languages use the functionality of the .NET Framework, which
provides access to key technologies that simplify the development of ASP Web applications and XML Web
Services.
Console applications are typically designed without a graphical user interface (GUI) and are compiled into
an executable file. You interact with a console application by typing instructions at the command prompt.
The Main method is the entry point of a C# application. (Libraries and services do not require a Main
method as an entry point.) When the application is started, the Main method is the first method that is
invoked. There can only be one entry point in a C# program. If you have more than one class that has a
Main method, you must compile your program with the StartupObject compiler option to specify which
Main method to use as the entry point.
2
2) Solved Lab Activites
Sr. No Allocated Time Level of Complexity CLO Mapping
Activity 1:
Install Visual Studio 2022
1. Check the system requirements. These requirements help you know whether your computer supports
Visual Studio 2022.
2. Apply the latest Windows updates. These updates ensure that your computer has both the latest
security updates and the required system components for Visual Studio.
3. Reboot. The reboot ensures that any pending installs or updates don't hinder your Visual Studio
install.
4. Free up space. Remove unneeded files and applications from your system drive by, for example,
running the Disk Cleanup app.
To do so, select the following button, choose the edition of Visual Studio that you want, and then save to
your Downloads folder.
Run the bootstrapper file to install the Visual Studio Installer. This new lightweight installer includes
everything you need to both install and customize Visual Studio.
1. From your Downloads folder, double-click the bootstrapper that matches or is similar to the following
file:
o vs_community.exe for Visual Studio Community
If you receive a User Account Control notice, choose Yes.
3
2. We'll ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy Statement.
Choose Continue.
After the installer is installed, you can use it to customize your installation by selecting the feature sets—
or workloads—that you want. Here's how.
4
Review the workload summaries to decide which workload supports the features you need. For example,
choose the ASP.NET and web development workload to edit ASP.NET Web pages with Web Live Preview
or build responsive web apps with Blazor, or choose from Desktop & Mobile workloads to develop cross-
platform apps with C#, or C++ projects that target C++20.
Next, status screens appear that show the progress of your Visual Studio installation.
1. After your Visual Studio installation is complete, select the Launch button to get started developing
with Visual Studio.
2. On the start window, choose Create a new project.
3. In the template search box, enter the type of app you want to create to see a list of available
templates. The list of templates depends on the workloads that you chose during installation.
You can also filter your search for a specific programming language by using the Language drop-down list.
You can filter by using the Platform list and the Project type list, too.
4. Visual Studio opens your new project, and you're ready to code!
Activity 2:
Developing first console based application in Visual Studio using .net framework.
In Visual Studio, a solution isn't an "answer". A solution is simply a container Visual Studio uses to organize
one or more related projects. When you open a solution, Visual Studio automatically loads all the projects
that the solution contains.
Create a solution
Start your exploration by creating an empty solution. After you get to know Visual Studio, you probably
won't create empty solutions very often. When you create a new project, Visual Studio automatically
creates a solution for the project unless a solution is already open.
1. Open Visual Studio, and on the start window, select Create a new project.
2. On the Create a new project page, type blank solution into the search box, select the Blank
Solution template, and then select Next.
5
'
3. On the Configure your new project page, name the solution QuickSolution, and then
select Create.
The QuickSolution solution appears in Solution Explorer on the right side of the Visual Studio
window. You'll use Solution Explorer often to browse the contents of your projects.
Add a project
Now add your first project to the solution. Start with an empty project, and add the items you need.
1. Right-click Solution 'QuickSolution' in Solution Explorer, and select Add > New Project from
the context menu.
2. On the Add a new project page, type empty into the search box at the top, and
select C# under All languages.
3. Select the C# Empty Project (.NET Framework) template, and then select Next.
4. On the Configure your new project page, name the project QuickDate, and then select Create.
The QuickDate project appears under the solution in Solution Explorer. Currently the project
contains a single file called App.config.
6
Add an item to the project
1. From the right-click or context menu of the QuickDate project in Solution Explorer,
select Add > New Item.
2. Expand Visual C# Items, and then select Code. In the middle pane, select the Class item
template. Under Name, type Calendar, and then select Add.
Visual Studio adds a file named Calendar.cs to the project. The .cs on the end is the file extension for C#
code files. The Calendar.cs file appears in the Solution Explorer visual project hierarchy, and the file
opens in the editor.
3. Replace the contents of the Calendar.cs file with the following code:
using System;
namespace QuickDate
{
internal class Calendar
{
static void Main(string[] args)
{
DateTime now = GetCurrentDate();
Console.WriteLine($"Today's date is {now}");
Console.ReadLine();
}
You don't need to understand everything the code is doing yet. Run the app by pressing Ctrl+F5, and see
that the app prints today's date to the console, or standard output, window. Then, close the console window.
7
Main Method
• The Main method is the entry point of an executable program; it is where the program control starts
and ends.
• Main is declared inside a class or struct. Main must be static and it need not be public. The
enclosing class or struct is not required to be static.
• Main can either have a void, int, or, starting with C# 7.1, Task, or Task<int> return type.
• If and only if Main returns a Task or Task<int>, the declaration of Main may include the
async modifier. This specifically excludes an async void Main method.
• The Main method can be declared with or without a string[] parameter that contains command-line
arguments. When using Visual Studio to create Windows applications, you can add the parameter
manually or else use the GetCommandLineArgs() method to obtain the command-line arguments.
Parameters are read as zero-indexed command-line arguments.
A C# console application must contain a Main method, in which control starts and ends. The Main method
is where you create objects and execute other methods.
The Main method is a static (C# Reference) method that resides inside a class or a struct. In the previous
example, it resides in a class named Calendar. You can declare the Main method in one of the following
ways:
It can return void.
8
It can also return an integer.
static int Main()
{ //...
return 0;
Or
static int Main(string[] args)
{
//...
return 0;
}
The parameter of the Main method, args, is a string array that contains the command-line arguments used
to invoke the program.
The call to ReadLine at the end of the Main method prevents the console window from closing before you
have a chance to read the output when you run your program in debug mode, by pressing F5.
C# programs generally use the input/output services provided by the run-time library of the .NET
Framework. The statement Console.WriteLine("…"); uses the WriteLine method. This is one of the output
methods of the Console class in the run-time library. It displays its string parameter on the standard output
stream followed by a new line. Other Console methods are available for different input and output
operations. If you include the using System; directive at the beginning of the program, you can directly use
the System classes and methods without fully qualifying them. For example, you can call
Console.WriteLine instead of System.Console.WriteLine:
using System;
Console.WriteLine("…");
9
3) Graded Lab Tasks
Lab Task 1
Develop a console based application using Visual C# to print your name, registration
number and address on console.
10