You are on page 1of 44

s.Shanmughavel Work shop on C#.

NET

Quick Glossary
BCL Base Class Library CLR Common Language Runtime GUI Graphic User Interface MSIL Microsoft Intermediate Language SCM Service Control Manager SOA Service Oriented Architecture ASP Active Server Pages ADO.NET ActiveX Data Object

AGENDA
Introduction to C# .NET C# Genealogy C# And .Net The Simple Stuff C# What is C# Why C# ? C# The Big Ideas Quick Comparison to Java Hello World Constructions of Note Introduction to Microsoft .NET Classic ASP Microsoft ASP.NET Server controls Data controls ASP.NET Web applications Web services Additional topics

Introduction to C#
Anders Hejlsberg
Distinguished Engineer Developer Division Microsoft Corporation

.NET is:

.NET

There are 50+ languages that generate MSIL


Most interoperate with each other

Microsofts Platform for Windows Development CLR the Virtual Machine that runs MSIL aka MicroSoft Byte Code BCL aka .NET Framework A set of compilers that can generate MSIL C#, Visual Basic, C++, Java (the MicroSoft flavor) http://www.dotnetpowered.com/languages.aspx

C# Genealogy
Elementary Procedural Advanced Procedural Special Procedural Object Oriented Eiffel Advanced Object Oriented

Fortran

Algol 68

C++

C#

Cobol

PL/I

Pascal

Ada 95

Java

Ada 83

C# And .Net
Languages like C# are not isolated entity They interoperate in two ways:
By being part of a system written in more than one language By accessing services and operating on a distributed environment

Requires support from run time:


.Net and the Common Language Runtime

.Net is many things, in particular binary object access C# interoperates with .Net

Most of C# is pretty similar to languages you are used to:


Declarations Expressions Assignment and control statements

The Simple Stuff

Other elements are quite similar:


Classes Functions Polymorphism

Language Created by Anders Hejlsberg (father of Delphi) The origin History can be viewed here: http://www.levenez.com/lang/history.html Principle Influencing Languages:
C++ Delphi Java

C#

Designed to be an optimal Windows development language

What is C#
C# is an object-oriented programming language developed by Microsoft. That intends to be a simple, modern, and generalpurpose programming language for application development. C#, also known as C-Sharp, is a programming language introduced by Microsoft. C# is specially designed to work with the Microsofts .NET platform.

Why C# ?
Builds on COM+ experience Native support for
Namespaces Versioning Attribute-driven development

Power of C with ease of Microsoft Visual Basic Minimal learning curve for everybody Much cleaner than C++ More structured than Visual Basic More powerful than Java

C# The Big Ideas


A component oriented language
The first component the C/C++ family oriented language in

In OOP a component is: A reusable program that can be combined with other components in the same system to form an application. Example: a single button in a graphical user interface, a small interest calculator They can be deployed on different servers and communicate with each other No header files, IDL, etc. Can be embedded in web pages

Enables one-stop programming

Whats the same


Quick Comparison to Java

Syntactically Similar Garbage Collected VM Environment Immutable Strings Exceptions (try / catch / finally) Object as root Single Inheritance model Multi-Interface model

Mono

Options Beyond MicroSoft

Open source development SDK for .NET Windows, Linux, Mac OS X, Solaris, Unix Sponsored by Novell Food for thought: Suse + KDE + Mono = ???

Sharp Develop
Open source IDE that uses .NET SDK or Mono Written in C#

Hello World
using System; class Hello { static void Main() { Console.WriteLine("Hello world"); } }

using

Constructions of Note

like import in Java: bring in namespaces

namespace
disambiguation of names like Internet hierarchical names and Java naming

class
like in Java single inheritance up to object

Console.Write(Line)

Constructions of Note

Takes a formatted string: Composite Format Indexed elements: e.g., {0}


can be used multiple times only evaluated once

{index [,alignment][:formatting]} also can use as in Java


Test + a

C# Program Structure Namespaces


Contain types and other namespaces Classes, and delegates structs, interfaces, enums,

Type declarations Members


Constants, fields, methods, properties, operators, constructors, destructors No header files, code written in-line No declaration order dependence indexers, events,

Organization

Application Console Application


Has standard streams (out, in, err) GUI can be added manually

Types

Windows Application
GUI based No standard streams (out, in, err) Main thread is shared by the GUI message pump & your code

Service
No standard streams (out, in, err) Main thread is commandeered by the SCM No GUI

Networking Namespaces

System.Messaging System.Net

Functionality for MSMQ Provides access to higher protocols (FTP, HTTP, DNS) Network information classes interface information, and ping providing statistics,

System.Net.Information System.Net.Sockets

System.Runtime.Remoting System.Web

Light weight wrappers around TCP and UDP sockets


Provides functionality for high programming (similar to RMI) level distributed

Windows Communications Foundation


Future of .NET Networking

Formally code named Indigo Designed to make SOA an integral part of Windows Tight coupling with .NET designs For more information
http://msdn.microsoft.com/windowsvista/default.aspx?pull=/l ibrary/en-us/dnlong/html/wcfarch.asp

Summary
C# builds on the .NET Framework component model New language with familiar structure
Easy to adopt for developers of C, C++, Java, and Visual Basic applications

Fully object oriented Optimized for the .NET Framework

Why do we need exceptions?

Exceptions

How should they be made available in programming languages? What benefits do they provide? What problems could they cause for us? Throw raises an exception Catch defines a block that handles the exception Etc.

One Thing Is For Sure


Exceptions are NOT for dealing with errors They are a mechanism for changing the flow of control from sequential to a branch if certain conditions exist They always indicate expected circumstances. Otherwise they could not possibly be generated

Introduction to .NET
ASP.NET
Visual Basic C++ C# JScript Common Language Specification Visual Studio.NET

ASP.NET: Web Services and Web Forms

Windows Forms

ADO.NET: Data and XML Base Class Library Common Language Runtime

ASP .Net and C#


Easily combined and ready to be used in WebPages. Powerful Fast Most of the works are done without getting stuck in low level programming and driver fixing and

Classic ASP
Successes
Simple procedural programming model Access to COM Objects
ADO File system object

No compiling, just save Support for multiple scripting languages Mix HTML and code VBscript leverage Visual Basic skills

Classic ASP
Code readability Coding overhead PostBack complexity Reuse Performance DLL locking Deployment Sessions Caching

Challenges

ASP.NET
Architecture

Compiled

.ASPX

ASP.NET Execution Model

Source code

Visual Basic
Compiler

C#
Compiler Assembly IL Code

C++
Compiler Assembly IL Code Unmanaged Component

Managed code

Assembly IL Code

Common Language Runtime


JIT Compiler
Native Code

Operating System Services

Server Controls
Simplify common tasks
Forms Tables Data display Calendar Ad rotator

Simplify Common Tasks

Server-side programming model Automatic browser compatibility Less code, less complexity Extensible

Server Controls
Validation
Without code
Required field Within range Two fields equal (password) Regular expressions Validation error messages Custom validation

With code, but simplified

Data Controls
Bind to many data sources
Collections
Array HashTable DataReader DataSet

ADO.NET

XML

Data Controls
ADO.NET
Connection Command DataReader DataSet DataAdapter DataView

ASP.NET Web Applications


web.config
Site configuration file Like an .INI file for your site XML format Extensible Some settings
Security Session Localization Tracing Debugging

Web Services
What Are Web Services?
Allow applications to communicate across the Internet Platform independent Protocol independent Synchronous/asynchronous Stateful/stateless ASP.NET

Additional Topics
Deployment
Copy Components in .\bin No registering DLLs No locked DLLs Apps are isolated Each app can have its own version Uninstall Delete

Additional Topics
Scalability Improvements
ASP.NET pages are complied State shared across machines Managed providers Disconnected data access Caching

Additional Topics
Authentication
Supports basic, digest, authentication, Passport Form-based authentication Users or roles One API for user info cookie, and Windows

ASP.NET
Features
ASPX, ASP side by side Simplified programming model Simplified deployment Better performance Caching Security Powerful controls

ASP.NET
Features
Simplified browser support Simplified form validation Code behind pages More powerful data access Web services Better session management

Useful Tools

Visual C# Express: Bing Visual C# Express in Visual Studio: MSDNAA must be version 2005: we need C# 2.0 Mono: http://www.go-mono.com Open Source impl for Linux: not quite at 2.0 Rotor: http://msdn.microsoft.com/net/sscli Shared Source impl for Windows (through 2.0) Used to work on BSD / OS X, too

Useful Tools
Portable.NET: http://www.dotgnu.org
yet another open source impl

CMS: http://cms.csuglab.cornell.edu
we will use this for homework turn on your email notifications!

44

You might also like