21
By Sam Nasr Nasr Information Systems May 14, 2013

By Sam Nasr Nasr Information Systems May 14, 2013

Embed Size (px)

Citation preview

By Sam Nasr

Nasr Information Systems

May 14, 2013

AgendaIntroductionWhat is .Net?.Net FrameworkAdvantages of .Net/CLR Visual StudioC# Syntax

IntroductionSam Nasr, MCAD, MCTS, MCTSoftware Developer since 1995Nasr Information SystemsPresident Cleveland C#/VB.Net User GroupPresident Cleveland WPF User GroupPresident .Net Study GroupINETA Mentor – OhioAuthor - Visual Studio Magazine

What is .Net? New programming methodology

Multiple Languages (VB.Net, C#, J#, etc.) IL JIT Compiler

Primary Parts:1. .Net Framework2. 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 FrameworkSupports Web Standards

HTMLXMLXSLTSOAPWSDL (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 LanguageMicrosoft proprietary languageOO LanguageHigh-level LanguagePrograms must be compiled before executed.Case sensitivePart 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 StatementThe 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 HandlingAn 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 ExceptionsWhat happens when the file c:\data.txt is not

found in this code?

Handling ExceptionsPlace 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 BlockThe 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

ResourcesC# Jumpstart Training:

https://www.microsoftvirtualacademy.com/training-courses/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 [email protected]

http://ClevelandDotNet.blogspot.com

@SamNasr

http://www.linkedin.com/in/samsnasr

Thank you for attending!