1 / 25

Overview

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). C# Types – Value types. true, false 0 – 255

donny
Télécharger la présentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. 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

  3. Type conversions • Types with smaller range can be implicitly converted to types with larger range • Other types MAY be explicitly convertedtarget_type outvar = (target_type) variableName

  4. Advanced types – enum • To constrain the possible values for a variable • Declared at same level as class • Plain text names associated with number

  5. Advanced types – struct • A custom, multi-valued, type that can have functions • Declared at same level as class • Can contain value types (int, long, double, etc) and strings

  6. Advanced types – Array • Making it easier to create/access groups of values of the same type

  7. Functions – Define and call Syntax: [scope][static] type name ([params]) { statements [return [value];] } Define: Call:

  8. Params by ref and by value

  9. Visual Studio Solutions … Visual Studio Solution (.sln) * Projects (.csproj)

  10. Layered Applications Presentation Layer BLL Business objects & logic Business Logic Layer DAL Read/Write data from/to a database Data Access Layer Data

  11. Steps to building a layered application • Get requirements for application feature(s) • Decide on a presentation layer and sketch it out(no code) • Create the … • Data access layer and tests, debug • Business logic layer and tests, debug • Presentation layer and connect to business layer, debug • Test the application • Create installer • Deploy application to users • Repeat until all application features are complete

  12. Creating a Business Layer • Add Class Library Project to Solution • Suffix name with BLL (e.g. IssueTrackerBLL) • Add classes to represent the business objects • Add properties and methods to these classes to represent the business data and processes respectively

  13. Testing a Business Layer • Create a Test Project • Common to have one Test Project per application Project • Suffix Test Project name with “Tests”

  14. Adding a Test

  15. Editing the TestMethod

  16. Running the test – no debugging With cursor in test method … Or right-click and use TestDriven.NET

  17. Running the test – with debugging With cursor in test method … Or right-click and use TestDriven.NET Need Breakpoint(F9 to toggle)

  18. Test results Test with MS Test Test with TestDriven.NET

  19. Building a Presentation Layer (UI) • Add UI Application Project that satisfies the requirements • Windows • Console Application • Windows Forms Application • WPF Application • Web • ASP.NET Web Application • ASP.NET MVC Application • Silverlight Application • This is the StartUp Project • Suffix Project name with UI (Optional)

  20. Command-line args for Console applications

  21. C# Compiler & command-line args

  22. Windows Forms Application • A Form is a container for UI controls • Common for starting form to have name MainForm Drag & Drop from Toolbox

  23. Naming child controls • Give child control names prefixes • btn = Button • txt = TextBox • lbl = Label • lst = ListBox • cbo = ComboBox • rdo = RadioButton • etc. • Adding code to controls … Double-click control or code by hand

  24. “Connecting” the UI and BLL Add Reference in UI to BLL Project Add using to UI code(MainForm.cs in this example)

  25. Example: Accessing BLL from UI

More Related