260 likes | 438 Views
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
E N D
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 ‘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 range • Other types MAY be explicitly convertedtarget_type outvar = (target_type) variableName
Advanced types – enum • To constrain the possible values for a variable • Declared at same level as class • Plain text names associated with number
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
Advanced types – Array • Making it easier to create/access groups of values of the same type
Functions – Define and call Syntax: [scope][static] type name ([params]) { statements [return [value];] } Define: Call:
Visual Studio Solutions … Visual Studio Solution (.sln) * Projects (.csproj)
Layered Applications Presentation Layer BLL Business objects & logic Business Logic Layer DAL Read/Write data from/to a database Data Access Layer Data
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
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
Testing a Business Layer • Create a Test Project • Common to have one Test Project per application Project • Suffix Test Project name with “Tests”
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 • 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)
Windows Forms Application • A Form is a container for UI controls • Common for starting form to have name MainForm Drag & Drop from Toolbox
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
“Connecting” the UI and BLL Add Reference in UI to BLL Project Add using to UI code(MainForm.cs in this example)