0% found this document useful (0 votes)
11 views

IT22-OOP1-Module-1

This document serves as a module for an Object Oriented Programming course, focusing on the Visual Studio IDE and its features for C# programming. It outlines the installation process, provides a step-by-step guide to creating a simple 'Hello World' application, and introduces concepts like refactoring and debugging. Additional resources and assessment details are also included for further learning.

Uploaded by

Joshua Riana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

IT22-OOP1-Module-1

This document serves as a module for an Object Oriented Programming course, focusing on the Visual Studio IDE and its features for C# programming. It outlines the installation process, provides a step-by-step guide to creating a simple 'Hello World' application, and introduces concepts like refactoring and debugging. Additional resources and assessment details are also included for further learning.

Uploaded by

Joshua Riana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

IT22-OOP1 (Object Oriented Programming 1)

PAMBAYANG DALUBHASAAN NG MARILAO


College of Computer Studies

I. INTRODUCTION
Visual Studio is a powerful tool/IDE in object
oriented programming. Giving programming
environment more easy to understand and
pleasing to the eyes. This module will give you a
tour on Visual Studio environment. This also
Module 1 teaches you on how to install and write your 1 st
program in C#.
INTRODUCTION TO
II. OBJECTIVES
C# 1. Reflect on the overview of the course
2. Distinguish the different elements of
Visual C# IDE
3. Understand the features of Visual C#
4. Understand how to install Visual C# and
how to open Visual C#
IV. LESSON PROPER
INTRODUCTION TO C# USING VISUAL STUDIO
The Visual Studio integrated development environment is a creative launching pad that you can use to
edit, debug, and build code, and then publish an app. An integrated development environment (IDE) is a
feature-rich program that can be used for many aspects of software development. Over and above the
standard editor and debugger that most IDEs provide, Visual Studio includes compilers, code completion
tools, graphical designers, and many more features to ease the software development process.

Page 1 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
This image shows Visual Studio with an open project and several key tool windows you'll likely use:

• Solution Explorer (top right) lets you view, navigate, and manage your code files. Solution
Explorer can help organize your code by grouping the files into solutions and projects.

• The editor window (center), where you'll likely spend a majority of your time, displays file
contents. This is where you can edit code or design a user interface such as a window with
buttons and text boxes.

• Team Explorer (bottom right) lets you track work items and share code with others using
version control technologies such as Git and Team Foundation Version Control (TFVC).

Popular productivity features

Some of the popular features in Visual Studio that help you to be more productive as you develop
software include:

Squiggles and Quick Actions

Squiggles are wavy underlines that alert you to errors or potential problems in your code as you type.
These visual clues enable you to fix problems immediately without waiting for the error to be discovered
during build or when you run the program. If you hover over a squiggle, you see additional information
about the error. A light bulb may also appear in the left margin with actions, known as Quick Actions, to
fix the error.

Code Cleanup

With the click of a button, format your code and apply any code fixes suggested by your code style
settings, .editorconfig conventions, and Roslyn analyzers. Code Cleanup helps you resolve issues in your
code before it goes to code review. (Currently available for C# code only.)

Refactoring

Refactoring includes operations such as intelligent renaming of variables, extracting one or more lines of
code into a new method, changing the order of method parameters, and more.

Page 2 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

IntelliSense

IntelliSense is a term for a set of features that displays information about your code directly in the editor
and, in some cases, write small bits of code for you. It's like having basic documentation inline in the
editor, which saves you from having to look up type information elsewhere. IntelliSense features vary by
language. For more information, see C# IntelliSense, Visual C++ IntelliSense, JavaScript IntelliSense,
and Visual Basic IntelliSense. The following illustration shows how IntelliSense displays a member list for
a type:

Install the Visual Studio IDE

To get started, download Visual Studio and install it on your system. The modular installer enables you
to choose and install workloads, which are groups of features needed for the programming language or
platform you prefer. To follow the steps for creating a program, be sure to select the .NET Core cross-
platform development workload during installation.

Page 3 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
Create a program

Let's dive in and create a simple program.

1. Open Visual Studio.

The start window appears with various options for cloning a repo, opening a recent project, or creating a
brand new project.

2. Choose Create a new project.

The Create a new project window opens and shows several project templates. A template contains the
basic files and settings needed for a given project type.

3. To find the template we want, type or enter .net core console in the search box. The list of
available templates is automatically filtered based on the keywords you entered. You can
further filter the template results by choosing C# from the Language drop-down list. Select
the Console App (.NET Core) template, and then choose Next.

Page 4 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

4. In the Configure your new project window, enter HelloWorld in the Project name box, optionally
change the directory location for your project files, and then choose Create.

Visual Studio creates the project. It's a simple "Hello World" application that calls
the Console.WriteLine() method to display the literal string "Hello World!" in the console (program
output) window.

Shortly, you should see something like the following:

Page 5 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

The C# code for your application shows in the editor window, which takes up most of the space. Notice
that the text is automatically colorized to indicate different parts of the code, such as keywords and
types. In addition, small, vertical dashed lines in the code indicate which braces match one another, and
line numbers help you locate code later. You can choose the small, boxed minus signs to collapse or
expand blocks of code. This code outlining feature lets you hide code you don't need, helping to
minimize onscreen clutter. The project files are listed on the right side in a window called Solution
Explorer.

Page 6 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
There are other menus and tool windows available, but let's move on for now.

5. Now, start the app. You can do this by choosing Start Without Debugging from the Debug menu
on the menu bar. You can also press Ctrl+F5.

Visual Studio builds the app, and a console window opens with the message Hello World!. You now have
a running app!

6. To close the console window, press any key on your keyboard.

7. Let's add some additional code to the app. Add the following C# code before the line that
says Console.WriteLine("Hello World!");:

C#Copy

Console.WriteLine("\nWhat is your name?");

var name = Console.ReadLine();

This code displays What is your name? in the console window, and then waits until the user enters some
text followed by the Enter key.

8. Change the line that says Console.WriteLine("Hello World!"); to the following code:

Page 7 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
C#Copy

Console.WriteLine($"\nHello {name}!");

9. Run the app again by selecting Debug > Start Without Debugging or by pressing Ctrl+F5.

Visual Studio rebuilds the app, and a console window opens and prompts you for your name.

10. Enter your name in the console window and press Enter.

11. Press any key to close the console window and stop the running program.

Use refactoring and IntelliSense

Let's look at a couple of the ways that refactoring and IntelliSense can help you code more efficiently.

First, let's rename the name variable:

1. Double-click the name variable to select it.

2. Type in the new name for the variable, username.

Notice that a gray box appears around the variable, and a light bulb appears in the margin.

3. Select the light bulb icon to show the available Quick Actions. Select Rename 'name' to
'username'.

The variable is renamed across the project, which in our case is only two places.

Page 8 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
4. Now let's take a look at IntelliSense. Below the line that says Console.WriteLine($"\nHello
{username}!");, type DateTime now = DateTime..

A box displays the members of the DateTime class. In addition, the description of the currently selected
member displays in a separate box.

5. Select the member named Now, which is a property of the class, by double-clicking on it or
pressing Tab. Complete the line of code by adding a semi-colon to the end.

6. Below that, type in or paste the following lines of code:

C#Copy

int dayOfYear = now.DayOfYear;

Console.Write("Day of year: ");

Console.WriteLine(dayOfYear);

Tip

Console.Write is a little different to Console.WriteLine in that it doesn't add a line terminator after it
prints. That means that the next piece of text that's sent to the output will print on the same line. You
can hover over each of these methods in your code to see their description.

7. Next, we'll use refactoring again to make the code a little more concise. Click on the
variable now in the line DateTime now = DateTime.Now;.

Notice that a little screwdriver icon appears in the margin on that line.

8. Click the screwdriver icon to see what suggestions Visual Studio has available. In this case, it's
showing the Inline temporary variable refactoring to remove a line of code without changing the
overall behavior of the code:

Page 9 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

9. Click Inline temporary variable to refactor the code.

10. Run the program again by pressing Ctrl+F5. The output looks something like this:

Debug code

When you write code, you need to run it and test it for bugs. Visual Studio's debugging system lets you
step through code one statement at a time and inspect variables as you go. You can set breakpoints that
stop execution of the code at a particular line. You can observe how the value of a variable changes as
the code runs, and more.

Let's set a breakpoint to see the value of the username variable while the program is "in flight".

1. Find the line of code that says Console.WriteLine($"\nHello {username}!");. To set a breakpoint
on this line of code, that is, to make the program pause execution at this line, click in the far left
margin of the editor. You can also click anywhere on the line of code and then press F9.

A red circle appears in the far left margin, and the code is highlighted in red.

Page 10 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

2. Start debugging by selecting Debug > Start Debugging or by pressing F5.

3. When the console window appears and asks for your name, type it in and press Enter.

The focus returns to the Visual Studio code editor and the line of code with the breakpoint is highlighted
in yellow. This signifies that it's the next line of code that the program will execute.

4. Hover your mouse over the username variable to see its value. Alternatively, you can right-click
on username and select Add Watch to add the variable to the Watch window, where you can
also see its value.

5. To let the program run to completion, press F5 again.

VI. ADDITIONAL RESOURCES


Microsoft Visual C# Step by Step, Ninth Edition by John sharp

Learn C3 in One Day and Learn it Well by Jamie Chan

VII. ASSESSMENT
To be given in separate worksheet.

Page 11 of 12
IT22-OOP1 (Object Oriented Programming 1)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

VIII. REFERENCES
https://www.c-sharpcorner.com/

https://www.w3schools.com/cs/

https://www.tutorialspoint.com/csharp/

https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/

Page 12 of 12

You might also like