IT7742 Advanced Programming
C# Module 1 - Complete Study Notes
Beginner-friendly detailed guide with real-world examples, C# rules, code examples, memory explanations,
exam definitions, and revision questions.
Topics covered: variables, data types, classes, objects, references, data members, static members,
methods, parameters, constructors, overloading, properties, getters/setters, encapsulation, access
modifiers, inheritance, overriding, operators, class types, method types, and a complete Person-Student
walkthrough.
IT7742 C# Module 1 Study Notes Page 1
Contents
1. C# and Object-Oriented Programming Fundamentals
2. Variables and Data Types
3. Classes, Objects and Object References
4. Data Members, Fields, Properties and Static Members
5. Methods (Functions) in C#
6. Parameters and Arguments
7. Constructors
8. Constructor Overloading and Constructor Chaining
9. Encapsulation, Getters and Setters
10. Access Modifiers
11. Inheritance
12. Method Overloading vs Method Overriding
13. Operators
14. Types of Classes and Methods
15. Complete Person-Student Example
16. Program Class and Execution Flow
17. Common Mistakes, Viva Questions and Revision Sheet
IT7742 C# Module 1 Study Notes Page 2
1. C# and Object-Oriented Programming Fundamentals
C# is a strongly typed, object-oriented programming language used with .NET. In object-oriented
programming, we model a program using classes and objects. A class describes what something should
contain and what it should be able to do; an object is a real instance created from that class.
Real-world analogy: An architect's house plan is a class. The actual houses built from that plan are objects.
One plan can be used to create many separate houses.
The main OOP ideas you are beginning to use are encapsulation, inheritance, polymorphism and
abstraction. Module 1 mainly builds the foundations needed to understand these.
Exam definition: Object-oriented programming is a programming approach that organizes software around
objects that contain data and behavior.
Important terminology
Term Meaning
Class Blueprint/type definition used to create objects.
Object An instance of a class.
Field A variable declared as part of a class.
Property Controlled interface for reading or writing data.
Method Named block of code representing behavior/action.
Constructor Special member used during object creation.
Reference A value that identifies/refers to an object.
Inheritance A derived class reuses/extends a base class.
Encapsulation Protecting internal state and controlling access.
IT7742 C# Module 1 Study Notes Page 3
2. Variables and Data Types
A variable is a named storage location used by a program to hold a value. Its declared data type tells C#
what kind of value the variable is allowed to represent.
Real-world analogy: Think of labeled containers. A container labeled 'Age' is intended for a number; a
container labeled 'Name' is intended for text.
Common C# data types
Type Stores Example
int Whole numbers 21
double Floating-point numbers 95.5
decimal High-precision decimal values, often money 199.99m
bool true or false true
char One character 'A'
string Text "Moiz"
Class type A reference to an object Student reference
C# is strongly typed: the compiler checks whether values are compatible with the declared types.
int age = 21;
string name = "Moiz";
bool enrolled = true;
double grade = 95.5;
Value types vs reference types
Value types hold their value directly. Examples include int, double, bool and char. Reference-type variables
hold a reference that can lead to an object. Classes are reference types.
For beginner learning, you can visualize local value-type variables as containing their values directly, while
a class-type variable such as student1 contains a reference to a Student object. Actual .NET memory
behavior has optimizations and details beyond the simple 'stack vs heap' teaching model.
Exam definition: A data type specifies the kind of data a variable can store and the operations that are
valid for that data.
IT7742 C# Module 1 Study Notes Page 4
3. Classes, Objects and Object References
A class is a programmer-defined type. It can define fields, properties, constructors and methods. An object
is a particular instance of that class.
Real-world example
Suppose Car is a class. It may define Brand, Model, Year and a Start() method. A black 2020 Toyota and a
white 2024 BMW are two different objects created from the same general Car blueprint.
class Car
{
public string Brand { get; set; }
public void Start()
{
[Link]("Car started");
}
}
Why isn't an object simply called a variable?
Because the concepts have different roles. A variable is a named location/reference used by the program.
The object is the actual instance containing state and behavior. A class-type variable normally refers to an
object.
Car car1 = new Car();
Breakdown: Car is the variable's type; car1 is the reference variable; new requests a new object; Car()
invokes construction of that object.
A useful conceptual diagram is: car1 -> Car object. Two different reference variables can even refer to the
same object.
Private access and references
Having an object reference does not bypass access control. Code outside a class cannot directly access that
class's private members merely because it has a reference to the object. Access is determined by where
the accessing code is declared.
Important: Code inside a class can access private members on another instance of the same class. The rule
is class-based, not 'this individual object only'.
IT7742 C# Module 1 Study Notes Page 5
4. Data Members, Fields, Properties and Static
Members
A data member is a member of a class that represents data/state. Fields and properties are common
examples.
Instance field
An instance field belongs to each individual object. If three Student objects exist, each can have its own
age.
class Student
{
private int age;
}
Static/shared data member
A static member belongs to the class itself rather than to one individual object. There is one shared
class-level member for that type.
Real-world example: Each student has a different student name (instance data), but the college name could
be shared by all students (static/class-level data).
class Student
{
public static int StudentCount = 0;
public string Name { get; set; }
}
A counter is useful for counting how many objects have been created, but a counter does not store those
objects. To manage many students, you normally use a collection such as List<Student>.
Field vs property
Field Property
Direct storage member Controlled access member
Often private Often public
Can hold actual backing data Can contain get/set logic
Usually lowercase/private naming Usually PascalCase
IT7742 C# Module 1 Study Notes Page 6
5. Methods (Functions) in C#
In C#, the usual term is method. A method is a named block of code inside a type that performs an action
or calculates/returns a result.
Real-world example: A BankAccount object may have Deposit(), Withdraw() and DisplayBalance() methods.
These describe what the object can do.
Characteristics of a method
• Has a name.
• May have an access modifier such as public or private.
• Has a return type, such as void, int, string, or a class type.
• May receive zero or more parameters.
• Contains a body (unless it is abstract/interface-style declaration).
• Can be instance-based or static.
• Can sometimes be overloaded or overridden depending on its declaration.
public void Study()
{
[Link]("Student is studying");
}
public int GetAge()
{
return 21;
}
The first method returns nothing, so its return type is void. The second promises to return an int.
Private methods
A method should be private when it is an internal helper that outside classes should not call directly. For
example, an ATM exposes Withdraw() publicly but may internally use private validation/calculation
methods.
Rule of thumb: expose only the operations other code genuinely needs. Keep implementation helpers
private where appropriate. This is part of encapsulation.
IT7742 C# Module 1 Study Notes Page 7
6. Parameters and Arguments
A parameter is a variable declared in a method or constructor definition. An argument is the actual value
supplied when the method/constructor is called.
public void SetAge(int age) // age is a parameter
{
[Link](age);
}
SetAge(21); // 21 is an argument
Real-world analogy: A restaurant order form has a blank called 'size' - that is like a parameter. When you
choose 'Large', the actual supplied choice is like an argument.
Getter and setter parameters
A normal property getter has no explicit parameter and returns the property's value. A normal setter has an
implicit value named value, supplied automatically by C# when a value is assigned to the property.
Exam definition: A parameter is a variable declared by a method/constructor to receive input; an
argument is the actual value passed to that parameter during a call.
IT7742 C# Module 1 Study Notes Page 8
7. Constructors
A constructor is a special class member that is invoked as part of creating an instance. Its main purpose is
to establish the object's initial state.
Core C# constructor rules
• A constructor has the same name as its class.
• It has no return type - not even void.
• It may have parameters.
• A class can have multiple constructors if their parameter lists differ.
• Instance constructors run during object creation.
• Constructors are not inherited in the same way methods are, although a derived constructor calls a base
constructor.
Real-world analogy: A new bank account cannot simply appear with no setup. During account creation, the
bank records the account holder, account number and initial configuration. That setup stage is like a
constructor.
class Student
{
public string Name { get; set; }
public Student(string name)
{
Name = name;
}
}
Method vs constructor
Constructor Method
Initializes an object Performs behavior/task
Same name as class Any valid method name
No return type Must declare a return type
Invoked during construction Called when needed
Can be overloaded Can be overloaded; some can be overridden
Common constructor categories
Type Meaning
Parameterless constructor Takes no parameters.
Parameterized constructor Takes one or more parameters.
Static constructor Initializes static/class-level state; runs automatically under CLR rules.
Private constructor Restricts instance creation from outside the class.
Copy-style constructor A user-defined constructor that accepts another instance and copies selected values; unlike C++, C#
IT7742 C# Module 1 Study Notes Page 9
8. Constructor Overloading and Constructor Chaining
Constructor overloading means defining multiple constructors in the same class with different parameter
lists. It gives different valid ways to initialize the same type.
Real-world example: A student registration system may allow registration with a name only, name + age,
or name + age + student ID.
class Student
{
public Student()
{
}
public Student(string name)
{
}
public Student(string name, int age)
{
}
}
C# selects the constructor whose parameter types/count match the supplied arguments.
Overloads must differ by the parameter signature. Merely changing parameter variable names is not
enough.
Constructor chaining with this
this(...) calls another constructor in the same class. It is useful for avoiding duplicated initialization logic.
public Student() : this("Unknown", 0)
{
}
public Student(string name, int age)
{
Name = name;
Age = age;
}
Constructor chaining with base
base(...) calls a constructor in the base/parent class. The base constructor executes before the derived
constructor body.
public Student(string name, int age) : base(name)
{
Age = age;
}
Execution idea: Student receives the arguments -> base(name) initializes the Person portion -> control
returns -> Student initializes its own portion.
IT7742 C# Module 1 Study Notes Page 10
9. Encapsulation, Getters and Setters
Encapsulation means keeping an object's internal state controlled and exposing an intentional interface for
interacting with it. A common beginner C# pattern is a private field with a public property.
Real-world analogy: A bank does not let customers directly edit the number representing their balance in
the database. Customers use controlled operations, and the system enforces rules.
private int age;
public int Age
{
get
{
return age;
}
set
{
if (value >= 0 && value <= 120)
{
age = value;
}
}
}
Getter
The getter runs when the property is read. A property getter does not declare a separate return type
because the property's declared type already determines what the getter returns. Here, Age is an int
property, so get must produce an int.
Setter
The setter runs when the property is assigned. It does not declare a return type. The incoming assigned
value is available through the implicit keyword value.
Data consistency
Validation in a setter can prevent invalid state. For example, rejecting an age below 0 or above a
reasonable maximum prevents nonsensical data from entering the object's field.
Auto-properties
public string Name { get; set; }
public int StudentId { get; private set; }
Auto-properties are concise when custom backing-field logic is unnecessary. A private setter allows outside
code to read the value while restricting where it can be assigned.
IT7742 C# Module 1 Study Notes Page 11
10. Access Modifiers
Access modifiers control where a type or member may be accessed. They are central to encapsulation.
Modifier Beginner meaning Typical use
public Accessible wherever the containing type itself is accessible
Public API of an object
private Accessible only within the containing type Internal implementation/state
protected Accessible within the containing type and derivedMembers
types (subject
intended
to C#
forprotected-access
inheritance rules)
internal Accessible within the same assembly Project/assembly-internal API
protected internal Same assembly OR derived-class access Library inheritance scenarios
private protected Derived-class access only within the same assembly
More restricted inheritance scenarios
Real-world analogies
• public: a public reception desk - intended for outside interaction.
• private: a locked staff-only internal safe - only the owning class operates it directly.
• protected: information shared within a family line - parent and derived classes.
• internal: employee-only company system - same assembly/project boundary.
Can a private member be accessed through a reference?
Not from unrelated outside code. A reference does not defeat private access. However, code declared
inside the same class may access private members of another object of that same class.
When is protected useful?
Suppose BankAccount is a base class and SavingsAccount and BusinessAccount derive from it. A protected
member can be useful when derived implementations genuinely need direct access while unrelated classes
should not have public access. In modern design, protected properties/methods are often preferable to
exposing mutable protected fields because they preserve more control.
Typical beginner design pattern
Fields are commonly private; properties/methods are public only when callers need them; helper methods
are private; members designed specifically for derived classes may be protected.
IT7742 C# Module 1 Study Notes Page 12
11. Inheritance
Inheritance allows a derived (child) class to reuse and extend accessible behavior/state defined by a base
(parent) class.
It models an is-a relationship: Student is a Person; Car is a Vehicle; Dog is an Animal.
class Person
{
public string Name { get; set; }
}
class Student : Person
{
public int Age { get; set; }
}
Here Student derives from Person. A Student can use the accessible Person members and add
Student-specific members.
What happens to private base data?
Private members remain part of the base-class implementation/state but are not directly accessible by
derived-class code. The derived class interacts with them through accessible base members such as
protected/public properties or methods.
Constructors and inheritance
Constructors are not inherited as callable members. When constructing a derived object, a base constructor
must run before the derived constructor body. If you do not explicitly specify a base constructor call, C#
attempts to call an accessible parameterless base constructor.
Is-a vs has-a
Relationship Example Technique
is-a Student is a Person Inheritance
has-a Car has an Engine Composition/association
has-many Course has many Students Collection/association
Benefits include code reuse, consistent shared behavior and polymorphism. Risks include excessive
coupling and complicated inheritance hierarchies, so inheritance should represent a genuine relationship
rather than simply being used to avoid typing code.
IT7742 C# Module 1 Study Notes Page 13
12. Method Overloading vs Method Overriding
These terms sound similar but represent different ideas.
Overloading
Overloading means multiple methods (or constructors) have the same name but different parameter
signatures. The compiler determines which overload matches the arguments.
void Print(string text) { }
void Print(string text, int copies) { }
Overriding
Overriding means a derived class supplies a new implementation for an inherited virtual/abstract member.
This is a key mechanism for runtime polymorphism.
class Animal
{
public virtual void Speak()
{
[Link]("Animal sound");
}
}
class Dog : Animal
{
public override void Speak()
{
[Link]("Bark");
}
}
Real-world example: All employees may have a Work() behavior, but Developer and Accountant can
implement that behavior differently.
Overloading Overriding
Usually same class/type family Requires inheritance relationship
Same name, different parameter signature Same overridable member signature
Compile-time overload resolution Runtime virtual dispatch can select override
Adds alternative ways to call Specializes inherited behavior
Important C# rule: a normal base method must be declared appropriately (commonly virtual or abstract) to
be overridden, and the derived implementation uses override.
IT7742 C# Module 1 Study Notes Page 14
13. Operators
An operator is a symbol or keyword that performs an operation on one or more operands.
In 10 + 5, 10 and 5 are operands and + is the operator.
Category Examples Purpose
Arithmetic +-*/% Mathematical operations
Assignment = += -= *= /= Assign/update values
Comparison == != > < >= <= Compare values; result is bool
Logical && || ! Combine/reverse Boolean conditions
Unary ++ -- ! - Operate on one operand
Conditional ?: Choose one of two values based on condition
Null-related ?? ?. ??= Work safely/concisely with null values
int total = 10 + 5;
bool adult = age >= 18;
bool allowed = hasId && adult;
count++;
string displayName = name ?? "Unknown";
Operator precedence determines which operations are evaluated first. Parentheses can make the intended
order explicit and easier to read.
Exam definition: An operator is a symbol or keyword that instructs C# to perform an operation on one or
more operands.
IT7742 C# Module 1 Study Notes Page 15
14. Types of Classes and Methods
Common class categories
Class type Meaning
Concrete/regular class Can normally be instantiated; provides implemented members.
Static class Cannot be instantiated; contains static members and is used for class-level utilities.
Abstract class Cannot be instantiated directly; designed as a base type and may contain abstract and implemented
Sealed class Cannot be used as a base class for further inheritance.
Common method categories
Method type Meaning
Instance method Called in relation to an object instance.
Static method Belongs to the type; no instance is required to call it.
Void method Returns no value.
Value-returning method Returns a value of its declared return type.
Parameterized method Receives one or more parameters.
Parameterless method Receives no parameters.
Overloaded method Shares its name with another overload but has a different parameter signature.
Virtual method Provides an implementation that derived classes may override.
Override method Derived implementation replacing a virtual/abstract inherited member.
IT7742 C# Module 1 Study Notes Page 16
15. Complete Person-Student Example
This example combines the major concepts we discussed: class, object, inheritance, encapsulation,
constructor, property validation, method calls and base-constructor execution.
using System;
class Person
{
private string name;
public string Name
{
get
{
return name;
}
set
{
if ()
name = value;
else
name = "Unknown";
}
}
public Person(string name)
{
Name = name;
}
public void DisplayPersonInfo()
{
[Link]($"Name: {Name}");
}
}
class Student : Person
{
private int age;
public int Age
{
get
{
return age;
}
set
{
if (value >= 0 && value <= 120)
age = value;
else
age = 0;
}
}
public Student(string name, int age) : base(name)
{
Age = age;
}
public void Study()
{
[Link]($"{Name} is studying.");
}
public void DisplayStudentInfo()
{
DisplayPersonInfo();
[Link]($"Age: {Age}");
}
}
IT7742 C# Module 1 Study Notes Page 17
class Program
{
static void Main()
{
Student student1 = new Student("Moiz", 21);
[Link]();
[Link]();
}
}
Person class explained
private string name; is the hidden backing field. Name is the public property. Its getter returns the field; its
setter validates incoming values. The Person constructor assigns through the property so the validation is
reused. DisplayPersonInfo() is a public instance method.
Student class explained
class Student : Person establishes inheritance. Student adds its own private age field and Age property. The
Student constructor receives name and age. : base(name) sends the name to Person's constructor before
the Student constructor body sets Age.
Why use properties inside constructors?
Assigning Name = name and Age = age routes the initial values through the same validation rules used for
later assignments. This avoids duplicating validation logic.
Expected output
Name: Moiz
Age: 21
Moiz is studying.
IT7742 C# Module 1 Study Notes Page 18
16. Program Class and Execution Flow
The Program class is not representing a real student. In this console example it contains the application's
entry point and coordinates object creation and method calls.
class Program
{
static void Main()
{
Student student1 = new Student("Moiz", 21);
[Link]();
[Link]();
}
}
static void Main() is the entry point in this style of C# console program. static means it belongs to the
Program type rather than requiring a Program instance. void means this version does not return a value.
Exact execution sequence
• Main begins.
• C# evaluates new Student("Moiz", 21).
• Storage for the new object is prepared and initialization begins.
• The Student constructor's base(name) invokes Person's constructor.
• Person assigns Name = name; the Name setter validates and stores "Moiz".
• The Person constructor completes.
• Control continues in the Student constructor.
• Age = age invokes the Age setter, which validates and stores 21.
• Construction completes and the resulting reference is assigned to student1.
• [Link]() is called.
• The inherited DisplayPersonInfo() prints the name, then the Student method prints the age.
• [Link]() prints that the student is studying.
• Main reaches its end and the console program completes.
Handling multiple students
The original example is intentionally small, but it is not limited to one student. You can create multiple
Student objects. A counter is not required for multiple objects; a counter only records a number.
Student student1 = new Student("Moiz", 21);
Student student2 = new Student("Ali", 20);
Student student3 = new Student("Sara", 19);
For a scalable program, use a collection such as List<Student> to store many student references.
List<Student> students = new List<Student>();
[Link](new Student("Moiz", 21));
[Link](new Student("Ali", 20));
[Link](new Student("Sara", 19));
A list answers 'which students are stored?'. A static counter can separately answer 'how many have been
created?'. They solve different problems.
IT7742 C# Module 1 Study Notes Page 19
17. Common Mistakes, Viva Questions and Revision
Sheet
Common beginner mistakes
• Calling a class and an object the same thing. A class is the type/blueprint; an object is an instance.
• Thinking a reference variable is the object itself. It refers to the object.
• Giving a constructor a return type. Constructors do not declare return types.
• Confusing an argument with a parameter.
• Making every field public and therefore losing control of state.
• Assuming protected means 'public to child objects from anywhere'. C# protected access has language
rules based on the accessing derived type/context.
• Confusing overloading with overriding.
• Assuming a counter stores objects. It only stores a count.
• Using inheritance for a has-a relationship.
• Calling a setter's implicit value a normal declared parameter. It is supplied automatically by the property
setter.
High-value viva questions
Question Short answer
What is a class? A programmer-defined type/blueprint for objects.
What is an object? An instance of a class.
What is an object reference? A value used to refer to an object.
Why use encapsulation? To protect state and control how it is accessed/changed.
What does a constructor do? Initializes an instance during object creation.
Can a constructor return a value? No; constructors do not declare return types.
What is overloading? Same member name with different parameter signatures.
What is overriding? Derived class supplies a new implementation of an overridable inherited member.
What does protected mean? Access intended for the containing type and derived types, under C# protected-access rules.
Are constructors inherited? No, but derived construction invokes a base constructor.
Getter return type? The property's declared type determines it; get itself does not declare a separate return type.
Setter return type? None is declared; set receives the implicit value.
Why private methods? To hide internal helper behavior from outside callers.
Inheritance relationship? Normally models an is-a relationship.
List vs counter? List stores references/items; counter stores only a number.
One-page memory sheet
Concept Remember
Variable Named storage/reference used by code.
Class Blueprint/type.
Object Instance.
Reference Points/refers to object.
Field Data member/storage in class.
IT7742 C# Module 1 Study Notes Page 20
Concept Remember
Property Controlled data access.
get Reads/returns property value.
set Receives assigned value and can validate.
Method Behavior/action.
Constructor Initial object setup; same name as class; no return type.
Overloading Same name, different parameters.
Inheritance Child/derived class reuses and extends base class.
Overriding Derived class changes inherited virtual behavior.
Encapsulation Hide/control internal state.
public Outside access allowed.
private Containing type only.
protected Containing + derived-class access.
static Belongs to the type, not one instance.
new Creates/initializes a new object instance.
base(...) Calls base constructor/member context.
this(...) Calls another constructor in same class.
Practice questions
• Explain the difference between a class, an object and an object reference.
• Why might a field be private while its property is public?
• Explain the difference between a constructor and a method.
• Give a real-world example of inheritance and identify the base and derived classes.
• Why is protected useful in inheritance?
• Explain parameter vs argument.
• Explain constructor overloading.
• Explain method overloading vs overriding.
• What happens when new Student("Moiz", 21) executes in the Person-Student example?
• Why would List be more useful than a simple counter for managing many students?
Final revision principle: Do not memorize C# as isolated keywords. Ask three questions for every line: (1)
What data/behavior does this represent? (2) Who should be allowed to access it? (3) Is it attached to one
object, shared by the class, or inherited from a base class?
IT7742 C# Module 1 Study Notes Page 21