62
Delivering Awesome Web Applications Developing Windows and Web Applications using Visual Studio.NET Peter Gfader

NET and C# introduction

Embed Size (px)

DESCRIPTION

What is .NET? What is C#? Language Differences VB + C# Review of OOP N-Tier Solution Design Creating WinForms applications

Citation preview

Page 1: NET and C# introduction

Delivering Awesome Web Applications

Developing Windows and Web Applications using Visual Studio.NET

Peter Gfader

Page 2: NET and C# introduction

Delivering Awesome Web Applications

Agenda

1. About SSW and Presenters

2. Student Introduction

3. Course Overview

4. .NET Overview

5. VS. Net Overview/ Demo

6. Design Patterns

7. Hands on lab

Page 3: NET and C# introduction

Delivering Awesome Web Applications

SSW Consulting has 18 years development / consulting experience.

Adam Cogan is the Chief Software Architect at SSW

1of 3 Microsoft Regional Directors in Australia

About SSW

Page 4: NET and C# introduction

Delivering Awesome Web Applications

SSA @ SSW

Loves C# and .NET (Java not anymore)

Specializes in

Windows Forms ASP.NET TFS testing Automated tests Silverlight

Peter Gfader

Page 5: NET and C# introduction

Delivering Awesome Web Applications

Attendance

Please initial the sheet next to your name

Hands On Lab

Please get Peter to initial sheet

Homework

Certificate

At end of 10 sessions

Admin Stuff

Page 6: NET and C# introduction

Delivering Awesome Web Applications

Name

Company

Experience

IT Programming .NET C# / VB Database

Goals for the course

Anything else after 9PM

Introductions

Page 7: NET and C# introduction

Delivering Awesome Web Applications

http://www.ssw.com.au/ssw/Events/2010UTSNET/

Part 1: .NET WinForms

1. Overview of .NET & C# basics2. C# Advanced + Data in Forms3. Usability - Rules to Better Windows Forms4. Deployment and Security of Windows Forms5. Web Services and Threading

The 10 Sessions

Page 8: NET and C# introduction

Delivering Awesome Web Applications

http://www.ssw.com.au/ssw/Events/2010UTSNET/default.aspx

Part 2: .NET Webforms

1. Overview of ASP.NET Webforms2. Data in Webforms3. Usability

• Rich Web Forms and • Other ASP.NET Features

4. Web Security 5. Advanced Topics & Future Technology

The 10 Sessions

Page 9: NET and C# introduction

Delivering Awesome Web Applications

What is .NET?

What is C#?

Language Differences VB + C#

Review of OOP

N-Tier Solution Design

Demo: Creating WinForms

Session 1: Overview

Page 10: NET and C# introduction

Delivering Awesome Web Applications

.NET is the Microsoft Web services strategy to connect information, people, systems, and devices through

software

Microsoft, beginning 2000

What is .NET?

Page 11: NET and C# introduction

Delivering Awesome Web Applications

An application development platform from Microsoft

Runtime (Virtual machine)

Tools

Languages, IDE, …

Rapidly develop secure and robust software

Web and Windows

Full support for object-oriented programming

What is .NET?

Page 12: NET and C# introduction

Delivering Awesome Web Applications

C# compiler

Intermediate Language

(MSIL)

Common Language Runtime

Compiles to MSIL

Represents codeindependent from src

Executes MSIL

Page 13: NET and C# introduction

Delivering Awesome Web Applications

What is .NET?

Language Independence VB C# F# C++ IronPython

Any language that supports the Common Language Runtime (CLR) Specification

Page 14: NET and C# introduction

Delivering Awesome Web Applications

C:\Windows\Microsoft.NET

Tools

Page 15: NET and C# introduction

Delivering Awesome Web Applications

2002 - .Net 1.0 / Visual Studio.NET

2003 - .Net 1.1 / Visual Studio 2003

2005 - .Net 2.0 / Visual Studio 2005

2007 - .Net 3.5 / Visual Studio 2008

2008 - .Net 3.5sp1 (added EDMX)

2010 - .Net 4.0/ VS.Net 2010

Details on http://shrinkster.com/1cu8

History of .NET and Visual Studio

Page 16: NET and C# introduction

Delivering Awesome Web Applications

Over 4500 classes that provides features such as:

• Data access and connectivity (ADO.NET)• User Interfaces (WinForms, WPF)• Web Applications (ASP.NET, Silverlight)• Network Communication (WCF)• Workflow (WF)

What is the .NET Framework?

Page 17: NET and C# introduction

Delivering Awesome Web Applications

Evolution

The whole .NET FX 3.5

http://shrinkster.com/1515

Only new types in .NET 4

http://shrinkster.com/1cu9

.NET Framework

Page 18: NET and C# introduction

Delivering Awesome Web Applications

Allows for language independence

Memory Management (allocation and de-allocation of memory)

Performs automatic garbage collection with the elimination of pointers

No more memory leaks (in theory at least!)

Exception Handling

Security (sandbox from the OS– cannot run malicious code)

Converts the IL byte code into runtime code

CLR =Common Language Runtime

Page 19: NET and C# introduction

Delivering Awesome Web Applications

Main programming language for .NET framework

Based on C

Object Oriented

Built with hindsight

Java Very similar to Java C++ Very similar to C++

A ‘modern language’ that did not inherit the ‘junk’ from C++ (eg header files, syntax)

C# ?

Page 20: NET and C# introduction

Delivering Awesome Web Applications

Variable declaration

bool isVeryLong;

Variable assignment

isVeryLong = false;

Control statements

if (yourInput.Length > 10){

isVeryLong = true;}

C# Basis

Page 21: NET and C# introduction

Delivering Awesome Web Applications

C# 1.0 – First Version

C# 2.0 – Everything that didn’t fit in 1.0

C# 3.0 – LINQ, functional influence

C# 4.0 – Dynamic Programming

C# 5.0 …

History C# - Anders Hejlsberg

Page 22: NET and C# introduction

Delivering Awesome Web Applications

OOP

Page 23: NET and C# introduction

Delivering Awesome Web Applications

Terms - I want you to know

#1 Inheritance

#2 Encapsulation

#3 Polymorphism

#4 Abstraction

Classes

Objects

Properties

Methods

Events

Page 24: NET and C# introduction

Delivering Awesome Web Applications

Class vs. Object

Object

Instance of a class “Car” has an

instance called “petersCar”

Class Defines abstract

characterizations of a “thing”

• Customer• Employee• Car

Blueprint or template

Page 25: NET and C# introduction

Delivering Awesome Web Applications

Properties

Changeable features of objects Eg. „Color“ of a car

Methods

Actions on an object Eg. Car has a method „Accelerate“

Events

Let other objects know about an action Eg. Car has an event „DoorOpened“

Terms

Page 26: NET and C# introduction

Delivering Awesome Web Applications

A "square" is a "shape"

#1 Inheritance

Page 27: NET and C# introduction

Delivering Awesome Web Applications

A "shape" defines a common property "Color"

A "square" inherits the property "Color"

Page 28: NET and C# introduction

Delivering Awesome Web Applications

Information hiding

E.g.A shape hides internal data

1st point 2nd point

#2 Encapsulation

Page 29: NET and C# introduction

Delivering Awesome Web Applications

A „Square" has internal fields like „_side“

Page 30: NET and C# introduction

Delivering Awesome Web Applications

Appear as another

Be used like another

#3 Polymorphism

Page 31: NET and C# introduction

Delivering Awesome Web Applications

var shapes = new List<IShapes>() {

new Square(“Red"),

new Rectangle(“Blue"),

new Triangle(“Red")

};

foreach (var shape in shapes) {

Console.WriteLine(shape.Color +

": " + shape.CalcSize());

}

#3 Polymorphism

Page 32: NET and C# introduction

Delivering Awesome Web Applications

Allows inheritance but no instantiation

#4 Abstraction

Page 33: NET and C# introduction

Delivering Awesome Web Applications

No instance of a "Shape"

Page 34: NET and C# introduction

Delivering Awesome Web Applications

VB.NET versus C#

Page 35: NET and C# introduction

Delivering Awesome Web Applications

Variables

Language Differences

' VB Dim FavouriteColour As String = "LightGreen"

// C#String FavouriteColour = "LightGreen";

Page 36: NET and C# introduction

Delivering Awesome Web Applications

Methods

Language Differences

'VB

Public Function GetName () As String

Public Sub DoSomething()

//C#

public string GetName() {}

public void DoSomething() {}

Page 37: NET and C# introduction

Delivering Awesome Web Applications

Events and Methods

Language Differences

Page 38: NET and C# introduction

Delivering Awesome Web Applications

VB Properties

Language Differences

Public Property FirstName() As String Get Return pFirstName End Get Set(ByVal value As String) pFirstName = value End SetEnd Property

Page 39: NET and C# introduction

Delivering Awesome Web Applications

C# Properties

Language Differences

private string firstName;

public String FirstName{

get{ return firstName }set{ firstName = value;}

}

Page 40: NET and C# introduction

Delivering Awesome Web Applications

Automatic Properties Feature

public String FirstName

{

get; set;

}

Notice no internal variable was declared?

It is created by the compiler

Saves typing and makes code neater

Properties since C# 3.0

Page 41: NET and C# introduction

Delivering Awesome Web Applications

Auto Implemented Properties

Collection Initializers

Named parameters

Optional parameters

Lambdas

Can span statements across multiple lines

Auto Implemented Properties

Collection Initializers (limited)

Named parameters

Optional parameters

Lambdas (limited)

Can span statements across multiple lines

.NET 3.5

Page 42: NET and C# introduction

Delivering Awesome Web Applications

Auto Implemented Properties

Collection Initializers

Named parameters

Optional parameters

Lambdas

Can span statements across multiple lines

Auto Implemented Properties

Collection Initializers

Named parameters

Optional parameters

Lambdas

Can span statements across multiple lines

.NET 4

Page 43: NET and C# introduction

Delivering Awesome Web Applications

Visual Studio 2010

Page 44: NET and C# introduction

Delivering Awesome Web Applications

Visual Studio 2010

Page 45: NET and C# introduction

Delivering Awesome Web Applications

Windows Forms

Page 46: NET and C# introduction

Delivering Awesome Web Applications

A UI Component

WinForm – a Window displayed by an application Web Forms are page hosted in a browser

What is a Form?

Page 47: NET and C# introduction

Delivering Awesome Web Applications

Textboxes

Buttons

Tool Strip Menu

Picture

Labels

Controls

Page 48: NET and C# introduction

Delivering Awesome Web Applications

Reuse a set of controls

e.g. Form with • Billing Address and • Shipping Address

Where an address consists of– Address line 1 – Address line 2 – Suburb – State– Post code

User Controls

Page 49: NET and C# introduction

Delivering Awesome Web Applications

Most controls have events

Examples• Clicked• TextChanged• Closing

Event Handlers

Can’t control the order the event gets handled

Events

Page 50: NET and C# introduction

Delivering Awesome Web Applications

"Programming"

Able to code in that language

"Understanding .NET“

Understanding the .NET Framework and technology

"Architecture“

Knowing when and what do and why

Architecture vs. Programming

Page 51: NET and C# introduction

Delivering Awesome Web Applications

N-Tier Application Simplified

Page 52: NET and C# introduction

Delivering Awesome Web Applications

Separate logic and data access from presentation Easier to maintain code Low-coupling

Modularity/Re-use business logic Easily add a different UI

• Web UI• Smart Phone UI

Team Development

Why n-tier?

Page 53: NET and C# introduction

Delivering Awesome Web Applications

Keep the users in mind

Page 54: NET and C# introduction

Delivering Awesome Web Applications

Keep the users in mind

Page 55: NET and C# introduction

Delivering Awesome Web Applications

WPF?

Page 56: NET and C# introduction

Delivering Awesome Web Applications

Windows Presentation Foundation

Rich Windows Applications

Great Architecture + Great Graphics

Rapid Prototyping

2D, 3D, Vector, Document Flow, Layouts, Composition, etc.

WPF in a nutshell

Page 57: NET and C# introduction

Delivering Awesome Web Applications

The 10 Sessions

Overview of .NET

OOP

Language Differences

n-Tier Application Architecture

Demo: Creating WinForms (C#)

Summary

Page 58: NET and C# introduction

Delivering Awesome Web Applications

Creating a Windows Form Application

1. Opening forms2. Menus3. Event handlers4. User controls

Hands ON LAB

Page 59: NET and C# introduction

Delivering Awesome Web Applications

The C# tutorial http://www.csharp-station.com/Tutorial.aspx

Online videos and training http://channel9.msdn.com/learn/courses/VS2010/

Nice video to OOPhttp://msdn.microsoft.com/en-us/beginner/cc963989.aspx

More on OOPhttp://en.wikipedia.org/wiki/Object-oriented_programming

Resources 1/2

Page 60: NET and C# introduction

Delivering Awesome Web Applications

Design patterns in C#http://www.dofactory.com/Patterns/Patterns.aspx

Winforms tips and trickshttp://peitor.blogspot.com/search/label/winforms

Use controls in Windows Forms!

http://www.telerik.com http://www.devexpress.com http://www.infragistics.com

Beginner Developer Learning Centerhttp://msdn.microsoft.com/en-us/beginner/default.aspx

Resources 2/2

Page 61: NET and C# introduction

Delivering Awesome Web Applications

3 things…

[email protected]

http://peitor.blogspot.com

Page 62: NET and C# introduction

Delivering Awesome Web Applications

Thank You!

Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA

ABN: 21 069 371 900

Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105

[email protected]