Overview Type conversions Advanced types enum struct array Function parameters by value and by...

25
Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing Presentation Layer (Console apps and Windows Forms apps)

Transcript of Overview Type conversions Advanced types enum struct array Function parameters by value and by...

Page 1: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Overview

Type conversions

Advanced typesenumstructarray

Function parameters by value and by reference

Layered ApplicationsBusiness Logic Layer & TestingPresentation Layer (Console apps and Windows Forms apps)

Page 2: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

C# Types – Value types

true, false

0 – 255

‘a’, ‘b’, ‘c’, ‘\t’, etc.

28-29 significant digits, ± 7.9 x 1028

15-16 significant digits, ± 5.0 x 10324 to ±1.7 x 10308

List of constants of same type - byte, sbyte, short, ushort, int, uint, long, or ulong

7 significant digits, ±3.4 x 1038

-2,147,483,648 to 2,147,483,647

–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

-128 to 127

-32,768 to 32,767

Group of related value types

0 to 4,294,967,295

0 to 18,446,744,073,709,551,615

0 to 65,535

Page 3: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Type conversions

Types with smaller range can be implicitly converted to types with larger rangeOther types MAY be explicitly converted target_type outvar = (target_type) variableName

Page 4: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Advanced types – enum

To constrain the possible values for a variableDeclared at same level as classPlain text names associated with number

Page 5: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Advanced types – struct

A custom, multi-valued, type that can have functions

Declared at same level as classCan contain value types (int, long, double, etc) and strings

Page 6: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Advanced types – Array

Making it easier to create/access groups of values of the same type

Page 7: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Functions – Define and callSyntax:[scope][static] type name ([params]){ statements [return [value];]}

Define:

Call:

Page 8: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Params by ref and by value

Page 9: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Visual Studio Solutions …

Projects (.csproj)*

Visual Studio Solution (.sln)

Page 10: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Presentation Layer

Layered Applications

Business Logic Layer

Data

Data Access Layer

BLLBusiness objects & logic

DALRead/Write data from/toa database

Page 11: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Steps to building a layered application

1. Get requirements for application feature(s)2. Decide on a presentation layer and sketch it

out(no code)

3. Create the …Data access layer and tests, debugBusiness logic layer and tests, debugPresentation layer and connect to business layer, debug

4. Test the application5. Create installer6. Deploy application to users7. Repeat until all application features are

complete

Page 12: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Creating a Business Layer

Add Class Library Project to SolutionSuffix name with BLL (e.g. IssueTrackerBLL)Add classes to represent the business objectsAdd properties and methods to these classes to represent the business data and processes respectively

Page 13: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Testing a Business Layer

Create a Test Project

Common to have one Test Project per application Project

Suffix Test Project name with “Tests”

Page 14: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Adding a Test

Page 15: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Editing the TestMethod

Page 16: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Running the test – no debugging

With cursor in test method …

Or right-click and use TestDriven.NET

Page 17: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Running the test – with debugging

With cursor in test method …

Or right-click and use TestDriven.NET

Need Breakpoint(F9 to toggle)

Page 18: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Test results

Test with MS Test

Test with TestDriven.NET

Page 19: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Building a Presentation Layer (UI)

Add UI Application Project that satisfies the requirements

WindowsConsole ApplicationWindows Forms ApplicationWPF Application

WebASP.NET Web ApplicationASP.NET MVC ApplicationSilverlight Application

This is the StartUp ProjectSuffix Project name with UI (Optional)

Page 20: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Command-line args for Console applications

Page 21: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

C# Compiler & command-line args

Page 22: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Windows Forms Application

A Form is a container for UI controlsCommon for starting form to have name MainForm

Drag & Drop from Toolbox

Page 23: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Naming child controls

Give child control names prefixesbtn = Buttontxt = TextBoxlbl = Labellst = ListBoxcbo = ComboBoxrdo = RadioButtonetc.

Adding code to controls … Double-click control or code by hand

Page 24: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

“Connecting” the UI and BLL

Add Reference in UI to BLL Project

Add using to UI code(MainForm.cs in this example)

Page 25: Overview Type conversions Advanced types enum struct array Function parameters by value and by reference Layered Applications Business Logic Layer & Testing.

Example: Accessing BLL from UI