Introduction to
PROGRAMMING 2A
PROG6221
Lecturer: Mr. Mpho Gift Doctor Gololo
Class contents
• Introduction about your lecturer
• Transition from Java to C#
• Module overview
• Learning Unit 1: LO 1 – 4: Today
• Learning Unit 2: Object-Oriented Programming
• Learning Unit 3: Advanced C# Programming
• Learning Unit 4: Windows Presentation Foundation
• Module assessment breakdown
• Integrated Curriculum Engagement (ICE) activities: 10 %
• Portfolio Of Evidence (POE): 90%
Transition from Java to C#
• C# is very similar to Java
• 70% Java, 10% C++, 5% Visual Basic, 15% new
As in Java As in C++
• Object-orientation (single inheritance) • Overloading (Operator)
• Interfaces • Pointer arithmetic in unsafe code
• Exceptions • Some syntactic details
• Threads
• Namespaces (like Packages)
• Strong typing
• Garbage Collection
• Reflection
• Dynamic loading of code
• ...
Transition from Java to C#
• C# is very similar to Java
• 70% Java, 10% C++, 5% Visual Basic, 15% new
Really new (compared to Java) “Syntactic Sugar"
• Reference and output parameters • Component-based programming-Properties-
• Objects on the stack (structs) Events
• Rectangular arrays • Delegates
• Enumerations • Indexers
• Unified type system • Operator overloading
• goto • foreach statements
• Versioning • Boxing/unboxing
• Attributes
• ...
Module overview – Learning Unit 1
• The Visual Studio IDE is a creative
launching pad that you can use to edit,
debug, and build code.
• The following types of applications can
be created using it:
• Console applications
• Rich Windows graphical user
interface (GUI) applications
• Class library
• Web applications
• ASP .NET Web services
• Windows as well as Web control
library
• Windows services
Module overview – Learning Unit 1
• Theme 1: C# and the .NET Platform
• LO1: Identify the building blocks of the .NET Platform;
• LO2: Explain the purpose of the common type system;
• LO3: Differentiate between assemblies, namespaces, and types;
• LO4: Explain the platform independent nature of .NET.
• Theme 2: Core C# Programming
• LO5: Write a console program that requires user input;
• LO6: Apply string manipulation to solve a programming problem;
• LO7: Use implicitly typed variables in a program;
• LO8: Explain the purpose of a nullable type.
Module overview – Learning Unit 2
• Theme 1: Encapsulation
• Refers to the building of data with the mechanism or methods that operate on the data, or
the limiting of direct access to some data
• Theme 2: Inheritance and Polymorphism
• Inheritance – the mechanism of basing an object or class upin another object
• Polymorphism – The ability to present the same interface for differing underlying forms
(data types)
• Theme 3: Structured Exception Handling
• The process of responding to the occurrence of exceptions – anomalous or exceptional
conditions
• Theme 4: Interfaces
• A completely "abstract class", which can only contain abstract methods and properties
(with empty bodies):
Module overview – Learning Unit 3
• Advanced C# Programming – Building upon OOP principles
• Theme 1: Collections and Generics
• Use a generic collection to solve a programming problem.
• Theme 2: Delegates, Events, and Lambda Expressions
• Use delegates to solve a programming problem;
• Use events to solve a programming problem;
• Differentiate between anonymous methods and lambda expressions.
Module overview – Learning Unit 4
• Theme 1: Introduction to the Windows Presentation Foundation
• Use Extensible Application Markup Language to create graphical user interfaces.
• Theme 2: Controls, Layouts, Events, and Data Binding
• Create GUI, API, etc..
• Theme 3: Graphics Rendering Services
• Use graphics rendering services to display graphical views of data.
• Theme 4: Resources, Animations, Styles, and Templates
• Styles in the user interface, use of animations to display visualizations of data, etc..
Module assessment breakdown
• Integrated Curriculum Engagement (ICE)
• Minimum number of ICE activities to complete: 4
• Weighting towards the final module mark: 10%
• Portfolio Of Evidence (POE)
• Weighting: 90%
• Duration: 15 hours
• Total marks: ICE (10%) + POE (90%) = 100 %
Software development process
• No typing without planning
• “If you fail to
Section plan, you are planning to fail.” – Benjamin Frankli
header
n
• Most difficult part is coming up with a plan not
programming
• Use different methodologies to solve computer
related problems
Software development process
Section header
Software development process
Once a customer or stakeholder has requested a project, the first step of
the SDLC is planning. This usually means looking into:
• Alignment: How does this project connect to your company’s larger
Section header
mission and goals?
• Resource availability and allocation: Do you have the people and tools
you need to take this on? Or do you need to hire a
new development team?
• Project scheduling: How does this project fit within your company’s
goals and other tasks?
• Cost estimation: How much is it going to cost?
Software development process
Requirements
• What problem does this solve?
Section header
• Who’s going to use it and why?
• What sort of data input/output is needed?
• Will you need to integrate with other tools or APIs?
• How will you handle security/privacy?
Software development process
Design and Prototyping
• With the requirements in place, it’s time to start designing what this
software will look
Section like and how it will function.
header
• create simple wireframes to show how interactions will work in the
software
• more user feedback and do a design sprint to quickly get a feature or
idea in front of your users.
Software development process
Software Development - Implementation
• With everyone onboard with the software’s proposed functionality and
design, it’s time to
Section build it according to the requirements and SOW.
header
• This phase is obviously the hardest and potentially riskiest stage of the
SDLC
• The goal here is to stick to the scope of the work, avoid scope creep,
and build clean, efficient software.
Software development process
Testing and Deployment
• simultaneously testing, tracking, and fixing bugs.
Section header
• releasing the product to a small group of beta testers or using UX tools
to track how users interact with it
• it’s important to make sure you’re not shipping buggy software to real
customers.
• With the heavy lifting (and coding) out of the way, it’s time to launch
your software to all of your users.
Software development process
Maintenance and Updates
• ending of one phase is just the beginning of another
Section header
• Requirements and customer needs are always evolving.
• it’s important to make sure you’re not shipping buggy software to real
customers.
• as people begin to use your software, they’ll undoubtedly find bugs,
request new features, and ask for more or different functionality.
• All of these requests need to flow back into your product backlog of
task list
Programming Methodologies
1. Structural Procedural Programing
• Process oriented focus on the processes that data undergoes
from input to output.
Section header
• Program
A sequence of procedure calls
• Procedure
Sequence of statements
• Example
calculator program that does addition, subtraction,
multiplication, division, square root and comparison
Programming Methodologies
2. Object-oriented Programming
• how to store data related to the entities
Section
• how header
the entities behave and how they interact with each other to give
a cohesive solution.
• Example
Payroll management system, we will have entities like
employees, salary structure, leave rules, etc. around which the
solution must be built.
Programming Methodologies
3. Functional Programming
• Here the problem, or the desired solution, is broken down into
functional units. Each unit performs its own task and is self-
Section header
sufficient. These units are then stitched together to form the complete
solution.
• Example
Payroll processing can have functional units like employee data
maintenance, basic salary calculation, gross salary calculation,
leave processing, loan repayment processing, etc.
Programming Methodologies
4. Logical Programming
• Here the problem is broken down into logical units rather than
functional units.
• Example
Section
header
In a school management system, users have very defined roles
like class teacher, subject teacher, lab assistant, coordinator,
academic in-charge, etc.
• Top-down approach
• Bottom-up approach
C# programming
• Syntax – writing set of rules to be followed
• Compilers checks syntax errors before converting info into
Section header
machine code
• Interpreters translate once line of code into intermediate
form
• Interpreters looks for rule violations line by line
C# programming
• Assemblers convert assembly language low level into
machine code
• Section header
Application Software – programs developed to perform a
specific task ie word, excel, etc
• DMSs ie SQL Server, Oracle, or Microsoft Access – designed to
organize large amount of data
Application Developed with C#
• Web applications – Use ASP.NET to create
apps that runs on the Web Server and deliver
functionality on the browser
• Windows Applications – desktop use apps
• Code written using C# and classes from
System.Windows.Forms
• Console Apps – send requests to the OS to
display text on the command console
C# - Program
• Comments //
• Inline Comments //
• Multiline comments /* */
• XML documentation Comments ///
• Using Directives
• using System – specify group of classes you
have to access
C# - Program
• Namespace
• Class Definition
• Interfaces – Class Iname
• Main() Method
• Method Body Statement
• Syntax
• Compilation and execution Process in visual
studio.
LU 1: 1 – building blocks of .Net Platform
• Difference between the Non .Net and the .Net Application execution
LU 1: 1 – building blocks of .Net Platform
• .NET Framework is a software platform for building systems on the Windows
family of operating systems, as well as on numerous non-Microsoft operating
systems such as macOS, iOS, Android, and various Unix/Linux d
• There are several benefits that can be derived from the use of .Net platforms:
1. Interoperability with existing code: Allows intermingling of old systems with newly developed
applications.
2. Support for numerous programming languages: (C#, Visual Basic, F#, and so on).
3. A common runtime engine shared by all .NET-aware languages
4. Language integration: .NET supports cross-language inheritance (e.g. C# and Visual Basic)
5. A comprehensive base class library: This library provides thousands of predefined solutions
6. A simplified deployment model: .Net platform allows multiple version of the same *.dll to exist in
harmony on a single machine
A DLL is a library that contains code and data that can be used by more than one program at the
same time.
LU 1: 1 – building blocks of .Net Platform
LU 1: 1 – CLR, CTS, and CLS
1. Common Language Runtime(CLR) : It is the runtime layer, its primary
role is to locate, load and mange .Net objects on programmer’s behalf.
• Takes care of low level details (memory management, application
hosting, coordinating threads and performing basic security checks.
2. Common Type system (CTS): describes all possible data types and all
programming constructs supported by runtime.
-specifies how entities can interact with each other and detail how they
are represented in .Net metadata.
3. Common Language Specification, or CLS: defines a subset of common
types and programming constructs that all .NET programming
languages can agree on. Thus, if you build .NET types that expose only
CLS-compliant features
LU 1: 1 – building blocks of .Net Platform
• The .NET Framework consists of several
elements.
• Together they provide the (IDE) developing
applications.
• Base Class Library - a set of classes
• The framework classes greatly simplify and
speed up many common development tasks
• The CLR is the foundation of the .NET
Framework.
• There are quite a few languages in which
developers could write .NET code.
• Visual Studio .NET is shipped with Visual
Basic .NET, C#, and managed extensions for
C++.
LU 1: 2 – Common Type System
• In.NET, type implies a member from the set
{class, interface, structure, enumeration,
Section header
delegate}.
• A .NET-aware language, interacts with types
• Understand the five types defined by the CTS in
their language of choice.
LU 1: 2 – CTS Class Types
• Supported by every .NET-aware language
• Is the cornerstone of OOP
• A class can have constructs, properties , methods and
Section
events andheader
data points(filed)
• Keyword class is used :
// A C# class type with 1 method.
class Calc
{
public int Add(int x, int y)
{
return x + y;
}
}
LU 1: 2 – CTS Class Types
Section header
LU 1: 2 – CTS Interface Types
• a named collection of abstract member definitions
• Supported by given class or structure
• Defined using interface keyword
Section header
// A C# interface type is usually
// declared as public, to allow types in other
// assemblies to implement their behavior.
public interface IDraw
{
void Draw();
}
LU 1: 2 – CTS Structure Types
• A structure can be // A C# structure type.
struct Point
thought of as a {
// Structures can contain fields.
lightweight class type public int xPos, yPos;
Section header
having value-based // Structures can contain
//parameterized constructors.
semantics. Supported by
public Point(int x, int y)
given class or structure { xPos = x; yPos = y;}
• structures are best // Structures may define methods.
public void PrintPosition()
suited for modeling {
geometric and Console.WriteLine("({0}, {1})",
xPos, yPos);
mathematical data }
}
LU 1: 2 – CTS Enumeration Types
• A handy programing construct that allow you to group
name-value pairs
• Default storage for each item is 32-bit integer
Section header
• The default storage slot can be altered if need be ie
when programing low-memory devices as mobile
// A C# enumeration type.
enum CharacterType
{
Wizard = 100,
Fighter = 200,
Thief = 300
}
LU 1: 2 – CTS Delegate Types
• Delegates are the .NET equivalent of a type-safe, C-style
function pointer.
• key difference is that a .NET
Section header
• delegate is a class that derives from
System.MulticastDelegate, rather than a simple pointer
to a raw memory address
// This C# delegate type can "point to" any method
// returning an int and taking two ints as input.
delegate int BinaryOp(int x, int y);
LU 1: 2 – CTS Type Members
• CTS defines various adornments that may be associated
with a given member
• Member visibility - public, private, protected
Section header
• Abstract declared members – enforce polymorphic
behavior on derived types
• Virtual declared – define a canned but overridable
implementation
• Static declared – bound at class level
• Instance – bound at object level
LU 1: 2 – CTS Type Members
Section header
LU 1: 2 System Data Types and Corresponding C#
Variable Declaration and Initialization:
• To declare a variable so by specifying the data type followed by
the variable’s name.
Section header
• Compile error – initialize a value before using it
static void LocalVarDeclarations()
{
Console.WriteLine("=> Data Declarations:");
// Local variables are declared as so:
// dataType varName;
int myInt;
string myString;
Console.WriteLine();
}
LU 1: 3 – assemblies, namespaces, and types
• Assembly is a binary unit that contains managed code within .net
core. Assembly may contain any number of distinct types. In the
world of .NET, type is simply a general term used to refer to a member
from the set {class, interface, structure, enumeration, delegate}.
• CTS is a formal specification that documents how types must be
defined in order to be hosted by the CLR.
LU 1: 3 – assemblies
• Used to avoid name conflicts (many classes with same name)
• Potential for name conflicts much higher in large projects or projects using
many external libraries
• Every class has to be inside a namespace
• Namespaces can be nested
• Classes from the vast library offered by the .NET framework
structured in vast hierarchy of namespaces
• Namespaces orthogonal to the structure of the source code
• There can be multiple namespaces in a single source file, a namespace can
span multiple source files
• The “using somenamespace;” directive gives he convenience of not
having to use fully qualified names for all classes
• May lead to name conflicts, compiler detects ambiguities
LU 1: 3 – Namespace
• A namespace is a grouping of semantically related types contained in
an assembly or possibly spread across multiple related assemblies.
For example, the System.IO namespace contains file I/O–related
types, the System.Data namespace defines basic database types, and
so on.
LU 1: 3 – Standard namespaces
• System contains classes that implement basic functionalities like
mathematical operations, data conversions etc.
• System.IO contains classes used for file I/O operations
• System.Collections.Generic contains classes that implement collections
of objects such as lists, hashtable etc. using C# generics
• System.Text contains classes that manipulate strings and text
• System.Diagnostics contains classes used in profiling and debugging
your application
LU 1: 4 - platform independent nature of .NET.
• .NET applications can be developed and executed on non-Microsoft operating systems, including
macOS, various Linux distributions, Solaris, and iOS and Android mobile devices.
Open Source .NET Distributions:
• The Mono project:
The Mono project is an open source distribution of the CLI that targets various Linux distributions
(e.g., SuSe, Fedora), macOS, iOS devices (iPad, iPhone), Android devices, and (surprise!) Windows.
• Xamarin SDK:
Xamarin grew from the Mono project and allows for developing cross-platform GUI
applications for mobile devices. The SDK is open sourced, while the full Xamarin product is not.
• .NET Core :
In addition to the Windows-centric .NET Framework, Microsoft also supports a
cross-platform version of .NET, which focuses on the construction of code libraries, data access, web
services, and web applications.