IntroToCS - Avon High School Tech Crew

advertisement
By
Sam Nasr
Nasr Information Systems
May 14, 2013
Agenda
 Introduction
 What is .Net?
 .Net Framework
 Advantages of .Net/CLR
 Visual Studio
 C# Syntax
Introduction
 Sam Nasr, MCAD, MCTS, MCT
 Software Developer since 1995
 Nasr Information Systems
 President Cleveland C#/VB.Net User Group
 President Cleveland WPF User Group
 President .Net Study Group
 INETA Mentor – Ohio
 Author - Visual Studio Magazine
What is .Net?

New programming methodology
 Multiple Languages (VB.Net, C#, J#, etc.)
 IL
 JIT Compiler

Primary Parts:
1. .Net Framework
2. Common Language Runtime (CLR)
- JIT Compiler

RTM: v4.5, since 2000
.Net Framework

A set of approximately 3500 classes.

Classes are divided into namespaces grouping similar classes.

For organization, each class belongs to only one namespace.

Most classes are lumped into a name space called System
 System.Data: DB access
 System.XML: reading/writing XML
 System.Windows.Forms: Forms manipulation
 System.Net: network communication.
.Net Framework
 Supports Web Standards





HTML
XML
XSLT
SOAP
WSDL (Web Services)
 ADO.Net: ActiveX Data Objects, EF
 ASP.Net: Active Server Pages
 Command Line Tools: ILDASM, ILASM, SN, etc.
Advantages of .Net

Write once, run everywhere with .Net FW

Multiple programming languages (20+)

Coding Reduction
 Controls
 Template projects
 IIS/Cassini support

Ease of Deployment

Security Features
Visual Studio
 IDE for development
 Templates for: Console app, Web Service, Win Service, ASP.Net, Class
Libraries
 Security tools
 VS Web Server (Cassini)
 Application Testing
 Team Suite for project management
 Express versions (free)
The C# Programming Language
 Microsoft proprietary language
 OO Language
 High-level Language
 Programs must be compiled before executed.
 Case sensitive
 Part of the .NET Framework, used for:
 ASP.Net
 Console Apps
 WF
 WCF
 WPF
 MVC
Elements of a C# Program
Data Types
Types of data in a program. Common data types are int (integers),
char (single character value), float (floating point values).
Variables
Provides temporary storage during program execution.
int number = 10;
Constants
Data fields whose value cannot be modified.
const int i = 10;
Arrays
A collection of items in which each item can be accessed by a unique
index.
int[] numbers = { 1, 2, 3, 4, 5 };
Operators
Symbols that specify which operation to perform on operands before
returning a result.
Methods
Methods are code blocks containing a series of statements. Methods
can receive input via arguments and can return a value to the caller.
Structure of a C# Program
The if-else Statement
 The if-else statement allows your program to perform one action if the
Boolean expression evaluates to true and a different action if the
Boolean expression evaluates to false.
Demo
Exception Handling
 An exception is an unexpected error condition that occurs
during program execution.
 When exception occurs, the runtime creates an exception
object and “throws” it.
 Unless you “catch” the exception, the program execution
will terminate.
 Exceptions are an object of the System.Exception class or
one of its derived classes.
 Example: DivideByZeroException exception object is
thrown when the program attempts to divide by zero.
 Example: FileNotFoundException exception object is
throws when the program cannot find a given file.
Unhandled Exceptions
 What happens when the file c:\data.txt is not found in
this code?
Handling Exceptions
 Place the code that throws the exceptions inside a try
block.
 Place the code that handles an exception inside a
catch block.
 You can have more than one catch blocks for each try
block. Each catch block handles a specific exception
type.
 A try block must have at least a catch block or a finally
block associated with it.
Exception Handling Sample
The finally Block
 The finally block is used in association with the try block.
 The finally block is always executed regardless of whether
an exception is thrown.
 The finally block is often used to write clean-up code.
try-catch-finally Example
Resources
 C# Jumpstart Training:
https://www.microsoftvirtualacademy.com/trainingcourses/developer-training-with-programming-in-c
 Community Megaphone: http://www.communitymegaphone.com/
 C#/VB.Net Special Interest Group: http://www.ClevelandDotNet.info/
 Cleveland WPF User Group: http://www.clevelandwpf.info/
 .Net Study Group: http://www.meetup.com/net-study-Group/
Contact Info
sam@nasr.info
http://ClevelandDotNet.blogspot.com
@SamNasr
http://www.linkedin.com/in/samsnasr
Thank you for attending!
Download