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

Post on 01-Apr-2015

236 views 1 download

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

Overview

Type conversions

Advanced typesenumstructarray

Function parameters by value and by reference

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

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

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

Advanced types – enum

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

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

Advanced types – Array

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

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

Define:

Call:

Params by ref and by value

Visual Studio Solutions …

Projects (.csproj)*

Visual Studio Solution (.sln)

Presentation Layer

Layered Applications

Business Logic Layer

Data

Data Access Layer

BLLBusiness objects & logic

DALRead/Write data from/toa database

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

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

Testing a Business Layer

Create a Test Project

Common to have one Test Project per application Project

Suffix Test Project name with “Tests”

Adding a Test

Editing the TestMethod

Running the test – no debugging

With cursor in test method …

Or right-click and use TestDriven.NET

Running the test – with debugging

With cursor in test method …

Or right-click and use TestDriven.NET

Need Breakpoint(F9 to toggle)

Test results

Test with MS Test

Test with TestDriven.NET

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)

Command-line args for Console applications

C# Compiler & command-line args

Windows Forms Application

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

Drag & Drop from Toolbox

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

“Connecting” the UI and BLL

Add Reference in UI to BLL Project

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

Example: Accessing BLL from UI