CPE261
Definition: An Intended Learning Outcome (ILO) is a clear and specific statement describing
what a learner is expected to know, understand, or be able to do after completing a course,
module, lesson, or educational activity.
Week 1 Lecture 2 – C# Fundamentals
By the end of the lesson, students should be able to:
1. write simple C# programs, demonstrating an understanding of the basic
syntax and structure of the C# programming language, including variables,
data types, and control flow statements.
2. use common .NET libraries and namespaces, such as System, to perform
tasks like string manipulation, file handling, and collection management in
their C# applications.
C# is Microsoft’s premier language for .NET development. It leverages time-tested
features with cutting-edge innovations and provides a highly usable, efficient way to write
programs for the modern enterprise computing environment.
C# inherits a rich programming legacy.
It is directly descended from two of the
world’s most successful computer languages: C
and C++.
C# Basic Syntax (Hello World!)
C# Program Structure
• The starting point of the program is:
static void Main ()
{
... starting point ...
}
This is known as the method Main(). A method is put inside a class. A class may be put
inside a namespace.
A program can contain several namespaces. A namespace can contain several classes. A
class can contain several methods. Think of a namespace as a container of classes. Think of a class
as a container of methods.
C# Reserved Words
A variable is used to store “data.” “It must be declared before it is being used.”
Syntax:
<data type> <name>;
<data type> <name_1>, <name_2>,..., <name_n>;
Example:
const double pi = 3.1416;
int id_num;
int num1, num2, num3, num4, num5;
Boolean Expression
Operators
Comparison
Equal ==
Not equal !=
Less <
Greater >
Less than or equal to <=
Greater than or equal to >=
Boolean
And &&
Or ||
Not !
Assignment Statement
• Assigning value to a variable
• Using the equal sign (=) when making assignments
Syntax:
<variable> = <expression>;
Example:
INPUT Statement
Console.ReadLine() //Returns a string
Use to get the input from user
Convert string to other data type
int.Parse()
Convert string to integer
double.Parse()
Convert string to double
Assignment 1:
1. Write a program for the following requirements:
a. Input: Your name
b. Output: Your name is <your name>.
2. Write a program for the following requirements:
a. Input: 3 numbers
b. Output: average of 3 input numbers. Note: You may round off the average value to
2 significant places.
3. Write a program for the following requirements:
a. Input: length of radius of circle
b. Output: Area of circle (Round off answer to 4 significant places.)
Note: Present screenshots of complete codes & outputs of test cases in MS Teams Class Notebook
under Assignment. Present at least 3 test cases.