c# programming: fundamentals

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

Upload: mahmoud-abdallah

Post on 14-Apr-2017

336 views

Category:

Software


0 download

TRANSCRIPT

Mahmoud Abdallah MahmoudFaculty of Engineering

Programming

[email protected]/in/mahmoudabdallah01

Introduction to Programming

1

Topics

• What is Programming

• Machine Code VS. Programming Languages

• Why C#

• Visual Studio (IDE)

• .NET Framework

• Windows Desktop (Console, Form) Applications

• DEMO

What is Programming ?

Programming

Every computer program is a set of instructions !

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

Sequence is vitally important

A lot more of instructions

Basic Fundamental Instructions

Most Popular Programming Languages

Why are there so many languages??

Machine Code

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

What is Technology ?

Why C#

IDE

.NET Framework

Windows Desktop Applications

Windows Form ApplicationsWindows Console Applications

Computer Programming

DEMO

Variables & Operators

2

Topics

• Variables

• Data Types

• Arrays

• Operators

• Examples

• DEMOs

What are Variables ?

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;

Data Types

• bool

• char

• string

• byte

• short

• int

• long

• float

• double

…..

Example 1

Example 2

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:

What are Operators ?

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

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

Operators

_ Operators are the things we can do to data.

Arithmetic: + - * / % ++ --

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

Logical: ! || &&

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

String Concatenation: +

Example 1

Example 2

Example 3

Demo

Decision Structures

3

Topics

• What are Decisions?

• IF Statement

• Inline Conditionals

• Switch Statement

• Examples

• DEMOs

What are Decisions?

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( ) { }

IF Statement_ For simple things.

Example 1

Example 2

Example 3

Demo

Inline Conditionals

Example

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

Example 1

Demo

Handling Repetitions

4

Topics

• What is Looping ?

• While

• Do While

• For

• For Each

• Continue

• Break

• What are Functions ?

• Arguments

• Return

What is Looping ?

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

While

_ Loop while a condition is true.

_ Checks condition at the beginning of the loop.

• Example 1: • Example 2:

Do While_ Loop while a condition is true.

_ Checks condition at the end of the loop.

Exam

ple

1

Example 2

For

_ Loop repeatedly until an expression evaluates to false.

_ Combines control elements in the for declaration.

• Example 1: • Example 2:

For Each

_ Loop through each element array or collection.

_ Used to iterate through items.

• Example 1:

Example 2

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:

Break

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

completely.

• Example:

What are Functions ?

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:

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:

Return

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

things back to us.

• Example 1:

Example 2

Demo

Basic Controls & Form Layout

5

Topics

• Event Driven Programming

• The Label Control

• Stateless Buttons

• Buttons with State

• Textbox Control

• Examples

• DEMOs

Event Driven Programming

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:

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

Example

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.

Example 1

Demo 1

Example 2

Demo 2

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

Example

Demo

Cont.

Design Elements

• ToolTip

• Anchor• Dock

• Tab Order

Contact Me

eg.linkedin.com/in/mahmoudabdallah01

[email protected]