C# Programing is an Object Oriented programming and it's multi-paradigm feature enable developers to develop various application project from small to large scale.
C# Programing support .NET Library and it's originally invented by Microsoft. Support in .NET Library make C# developer develop software easier.
This chapter covers Basic C#, Decision Making and Program Structure.
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
C# programming : Chapter One
1. XAMARIN MOBILE APPLICATION
DEVELOPMENT COURSE
Portable Class Library (PCL) using C#
Chapter 2
- Basic to C# Programming -
Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
2. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
What is C# Programming?
C# (pronounced "C-sharp") is an object-oriented programming language from
Microsoft that aims to combine the computing power of C++ with the
programming ease of Visual Basic. C# is based on C++ and contains features
similar to those of Java.
• Object Oriented
• Multi Paradigm
Visual Studio 2015. Updated: July 20, 2015. C# (pronounced "C sharp") is a
programming language that is designed for building a variety of applications
that run on the .NET Framework. C# is simple, powerful, type-safe, and object-
oriented.
3. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Output : Hello World
4. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Terms Explanation
+ Using
+ Namespace
+ Class
+ Main
5. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Terms Explanation
+ Using
This command are use to call (include)
another namespace or library.
After this call has been made, all variables,
classes & methods can be accessed by
current program / namespace.
This command also use to access property
from another namespace or properties.
Example are as the above-right.
This command has it’s own code block which is
every code write are only available or active on it’s
own code block.
//open of a code block
//close current code block
6. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Terms Explanation
+ Namespace
Namespace is a collection of classes.
In other word, we could say namespace is a
name of a program which is contains all
functions/methods, variables and classes of
a current programs.
Namespace has its own code block.
The state codes are only active /
accessible in its current namespace.
7. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Terms Explanation
+ Class
Class is a child code block for a namespace.
It contains methods / functions, variables
and child classes. For two or more classes
in a namespace it called as member class.
Classes has its own property called access
specifier.
For class without access specifier (like the
example ‘class HelloWorld’), automatically
the class is defined as an Internal Class.
8. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Program Structure
Terms Explanation
+ Main
In this example, main is a method /
function. Main method is a method where
program firstly read and run.
Every method has its own type of return
value, method type and access specifier.
The picture shows that static is a type of
method and void is a return value type
Void is use to tell the program that the
current method has no return value.
Static use to define
9. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Access Specifier
Access specifier is a definition of class, method and variable. This definition are required by
program to define the accessibility to other class and method.
Public Can be access publicly to other class even in other namespace
Private Only can be access in current method, class or namespace
Internal
Can be access within the program that contain its declarations and within the
same assembly
10. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Data Type
Access specifier is a definition of class, method and variable. This definition are required by
program to define the accessibility to other class and method.
Int Integer, numbers without decimal point
String Text
Bool Boolean, yes or no OR 1 or 0
long Integer that has long values.
Decimal Number with decimal point
Float Number with decimal point
Double Number with decimal point
11. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Methods
A method is a group of statements that together perform tasks. Every C# program has at least one
class with a method named Main (the default, first read and run by program).
Method code block or Do-Something-Here
REMINDER!
Access specifier are as
mentioned before.
Return type are as Data
Type mentioned before.
“VOID” type are used IF
the method has no value
to return.
Parameter list is where to put the variable from outside of the method to
use it inside the method.
To write parameter, its required to put Data Type and variable name.
12. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Anonymous Methods
Anonymous methods provide a technique to pass a code block as a delegate parameter.
Anonymous methods are the methods without a name, just the body.
You need not specify the return type in an anonymous method; it is inferred from the return
statement inside the method body.
13. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Classes
REMINDER!
Access specifier are as
mentioned before.
Class code block contains classes, methods & variables
A class is a construct that enables you to create your own custom types by
grouping together variables of other types, methods and events. A class is like a
blueprint. It defines the data and behaviour of a type.
14. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Conversion
• String – ToString, string.Format
• Int (16, 32, 64) – ToInt16, ToInt32, ToInt64
• Decimal - ToDecimal
15. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Decision Making
If Else Else If Else
16. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Decision Making
Switch Case
17. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Loops
While Loop
18. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Loops
For Loop
19. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Object Oriented Programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects",
which may contain data, in the form of fields, often known as attributes; and code, in the form of
procedures, often known as methods.
OOP is a solution to state object programmatically.
Example:
Defining cars programmatically.
The code on the left show how to define “Cars”
programmatically. It’s a list of car’s properties.
20. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Object Oriented Programming
The code on the left show how to create a new
car. In programming, its called new instance.
Use the dot (.) symbol to access object or class
child variables, methods or classes.
21. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Practice Make Perfect
Please create a program to collect contacts information.
In the contact, must have the name, email and phone number.
Please create a program to collect contacts information.
In the contact, must have the name, email and phone number.
TIPS!
• Create a new Contact class with variable
name, email and phone number
• Create new instance for every new
contact.
22. Written by : Mr Hery Copyright® HeryIT® JM0670283-X (2017)
Thank You
Thank you!
You re ready for next course.