Top Banner
Mahmoud Abdallah Mahmoud Faculty of Engineering Programming [email protected] eg.linkedin.com/in/mahmoudabdallah01
82

C# Programming: Fundamentals

Apr 14, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: C# Programming: Fundamentals

Mahmoud Abdallah MahmoudFaculty of Engineering

Programming

[email protected]/in/mahmoudabdallah01

Page 2: C# Programming: Fundamentals

Introduction to Programming

1

Page 3: C# Programming: Fundamentals

Topics

• What is Programming

• Machine Code VS. Programming Languages

• Why C#

• Visual Studio (IDE)

• .NET Framework

• Windows Desktop (Console, Form) Applications

• DEMO

Page 4: C# Programming: Fundamentals

What is Programming ?

Page 5: C# Programming: Fundamentals

Programming

Page 6: C# Programming: Fundamentals

Every computer program is a set of instructions !

Page 7: C# Programming: Fundamentals

Specific, individual, simple, clear, self-contained instructions

Page 8: C# Programming: Fundamentals

Sequence is vitally important

Page 9: C# Programming: Fundamentals

A lot more of instructions

Page 10: C# Programming: Fundamentals

Basic Fundamental Instructions

Page 11: C# Programming: Fundamentals

Most Popular Programming Languages

Page 12: C# Programming: Fundamentals

Why are there so many languages??

Page 13: C# Programming: Fundamentals

Machine Code

Page 14: C# Programming: Fundamentals

They are invented languages to bridge the gap between humans and machines

Page 15: C# Programming: Fundamentals

What is Technology ?

Page 16: C# Programming: Fundamentals

Why C#

Page 17: C# Programming: Fundamentals

IDE

Page 18: C# Programming: Fundamentals

.NET Framework

Page 19: C# Programming: Fundamentals

Windows Desktop Applications

Windows Form ApplicationsWindows Console Applications

Page 20: C# Programming: Fundamentals

Computer Programming

Page 21: C# Programming: Fundamentals

DEMO

Page 22: C# Programming: Fundamentals

Variables & Operators

2

Page 23: C# Programming: Fundamentals

Topics

• Variables

• Data Types

• Arrays

• Operators

• Examples

• DEMOs

Page 24: C# Programming: Fundamentals

What are Variables ?

Page 25: C# Programming: Fundamentals

Variables_ Variables are simply containers.

_ We create variables to hold data.

• Name

_ so we can retrieve it when we need to use it, or if we need to put data into the variable. Then we can access it by its name.

• Data type

_ The type of data that we can put inside a variable and it is also will determine the size of the variable.

Example:

int x;

x = 5;

Page 26: C# Programming: Fundamentals

Data Types

• bool

• char

• string

• byte

• short

• int

• long

• float

• double

…..

Page 27: C# Programming: Fundamentals

Example 1

Page 28: C# Programming: Fundamentals

Example 2

Page 29: C# Programming: Fundamentals

Arrays

_ Array: is a variable that can contain other variables, many variables and then we can reference them by index to pull them out.

Examples:

Page 30: C# Programming: Fundamentals

What are Operators ?

+ - * / % ++ --> < >= <= == !=

! || &&= += -= *= /= %=

Page 31: C# Programming: Fundamentals

Operators

_ Operators are the things we can do to data.

Arithmetic: + - * / % ++ --

Comparison: > < >= <= == !=

Logical: ! || &&

Assignment: = += -= *= /= %=

String Concatenation: +

Page 32: C# Programming: Fundamentals

Example 1

Page 33: C# Programming: Fundamentals

Example 2

Page 34: C# Programming: Fundamentals

Example 3

Page 35: C# Programming: Fundamentals

Demo

Page 36: C# Programming: Fundamentals

Decision Structures

3

Page 37: C# Programming: Fundamentals

Topics

• What are Decisions?

• IF Statement

• Inline Conditionals

• Switch Statement

• Examples

• DEMOs

Page 38: C# Programming: Fundamentals

What are Decisions?

Page 39: C# Programming: Fundamentals

Decision Structures

_ Gives our application the ability to make decisions.

_ Controlling the flow of how our program executes code.

_ What code executes based on conditions.

• if( ) { }

• switch( ) { }

Page 40: C# Programming: Fundamentals

IF Statement_ For simple things.

Example 1

Page 41: C# Programming: Fundamentals

Example 2

Page 42: C# Programming: Fundamentals

Example 3

Page 43: C# Programming: Fundamentals

Demo

Page 44: C# Programming: Fundamentals

Inline Conditionals

Example

Page 45: C# Programming: Fundamentals

Switch Statement_ When we have a lot of conditions, that were things get more complicated.

Example 1

Page 46: C# Programming: Fundamentals

Demo

Page 47: C# Programming: Fundamentals

Handling Repetitions

4

Page 48: C# Programming: Fundamentals

Topics

• What is Looping ?

• While

• Do While

• For

• For Each

• Continue

• Break

• What are Functions ?

• Arguments

• Return

Page 49: C# Programming: Fundamentals

What is Looping ?

Page 50: C# Programming: Fundamentals

Looping

_ Looping: Executes a block of code until a condition is met.

_ It is our way of running a piece of code multiple times.

• Loop Types:

_ While

_ DoWhile

_ For

_ ForEach

Page 51: C# Programming: Fundamentals

While

_ Loop while a condition is true.

_ Checks condition at the beginning of the loop.

• Example 1: • Example 2:

Page 52: C# Programming: Fundamentals

Do While_ Loop while a condition is true.

_ Checks condition at the end of the loop.

Exam

ple

1

Page 53: C# Programming: Fundamentals

Example 2

Page 54: C# Programming: Fundamentals

For

_ Loop repeatedly until an expression evaluates to false.

_ Combines control elements in the for declaration.

• Example 1: • Example 2:

Page 55: C# Programming: Fundamentals

For Each

_ Loop through each element array or collection.

_ Used to iterate through items.

• Example 1:

Page 56: C# Programming: Fundamentals

Example 2

Page 57: C# Programming: Fundamentals

Continue

_ It allows us to immediately end an iteration of the loop and go

back to the top of the loop and the next iteration.

• Example:

Page 58: C# Programming: Fundamentals

Break

_ If the break keyword is found, we are going to exit the loop

completely.

• Example:

Page 59: C# Programming: Fundamentals

What are Functions ?

Page 60: C# Programming: Fundamentals

Functions_ They are very useful for extracting reusable code.

_ We want to isolate some pieces of useful code and sort of store them in a function.

_ They are only useful if we actually call or invoke them.

_ Every function has two things: Declaration & Definition.

• Example:

Page 61: C# Programming: Fundamentals

Arguments

_ Arguments are things we can pass into a function and it will do something to them.

_ The function is a factory. We put things into the factory and we get things out of

the factory.

• Example:

Page 62: C# Programming: Fundamentals

Return

_ Return allows us to pass something into our function and then it is going to kick

things back to us.

• Example 1:

Page 63: C# Programming: Fundamentals

Example 2

Page 64: C# Programming: Fundamentals

Demo

Page 65: C# Programming: Fundamentals

Basic Controls & Form Layout

5

Page 66: C# Programming: Fundamentals

Topics

• Event Driven Programming

• The Label Control

• Stateless Buttons

• Buttons with State

• Textbox Control

• Examples

• DEMOs

Page 67: C# Programming: Fundamentals

Event Driven Programming

Page 68: C# Programming: Fundamentals

The Label Control

_ Labels basically are static text that will appear on a form.

_ Labels can be placeholders for data from database or a stuff was pulled from

somewhere else or to the user.

Example:

Page 69: C# Programming: Fundamentals

Stateless Buttons

_ A button is basically a control on the screen that you click or you press a key onto

and it performs some simple action.

_ It doesn’t keep track of any thing, it is just a stateless button.

_ Clicking a button fires an event called click event meaning that you have clicked this

button.

_ So what we can do is we can double click on this button to create our click event.

• Accept button

• Cancel button

Page 70: C# Programming: Fundamentals

Example

Page 71: C# Programming: Fundamentals

Buttons with State

_ Buttons that keep track of their current state.

• Radio buttons

• Check boxes

• Grouping:

_ Basically a container we can use to separate items.

_ Allows to have multiple sections of radio buttons.

Page 72: C# Programming: Fundamentals

Example 1

Page 73: C# Programming: Fundamentals

Demo 1

Page 74: C# Programming: Fundamentals

Example 2

Page 75: C# Programming: Fundamentals

Demo 2

Page 76: C# Programming: Fundamentals

Textbox Control

_ Allows us to write things to the user and read things from the user.

_ It is basically a control that contains text, and the text unlike the label is

editable at runtime by the user.

• Text property

• Multiline textbox

• Password box

Page 77: C# Programming: Fundamentals

Example

Page 78: C# Programming: Fundamentals

Demo

Page 79: C# Programming: Fundamentals

Cont.

Page 80: C# Programming: Fundamentals

Design Elements

• ToolTip

• Anchor• Dock

• Tab Order

Page 81: C# Programming: Fundamentals
Page 82: C# Programming: Fundamentals

Contact Me

eg.linkedin.com/in/mahmoudabdallah01

[email protected]