what is - mmu, mullana - north india's best university in ... content/mca_504(c)+.net...what is...
TRANSCRIPT
What Is .NET
It is a platform neutral framework.
It is a layer between the operating system and the programming language.
.NET is not an operating system and it is not a programming language.
It supports many programming languages including VB.Net,C# etc.
.Net is a new framework for developing web-based and window-based applications within the Microsoft environment.
Microsoft.NET Platform
Microsoft.NET
X
M
L
Internet
Protocols
Built on XML and Internet Protocol
Set of tools and services for developing new generation of software
.NET will run in any browser on any platform
Makes it quick and easy to design, implement, and deploy collaborative web solutions
Microsoft.NET
X
M
L
Internet
Protocols
Separates actual data from presentation
XML was designed to carry data, not to display data
XML tags are not predefined. You must define your own tags
XML stands for EXtensible Markup Language
Microsoft.NET
X
M
L
Internet
Protocols
Microsoft.NET is built existing protocols such as HTTP & SOAP
SOAP is an XML/HTTP-based protocol
SOAP allows access to services, objects,and server in a platform-independent manner
SOAP stands for Simple ObjectAccess Protocol
.NET FRAMEWORK
• The .NET Framework is a software framework forMicrosoft Windows operating systems.
• It includes a large library, and it supportsseveral programming languages which allows languageinteroperability
• It Supports over 40 different programming languages.
• The framework's Base Class Library provides userinterface, data access, database connectivity, webapplication development .
Base Class Library
Common Language Specification
Common Language Runtime
ADO.NET: Data and XML
VB VC++ VC#V
isu
al S
tud
io.N
ET
ASP.NET: Web Forms
JScript …
Windows
Forms
Framework, Languages, And Tools
The .NET framework consists of two parts:-
COMMON LANGUAGE RUNTIME
BASE CLASS LIBRARIES
Common Language Runtime(CLR)
CLR works like a virtual machine in executing all languages.
The purpose of the Common Language Infrastructure, is to
provide a language-neutral platform for application
development and execution,
Provide functionality will not be tied to a single language but
will be available across the many languages supported by the
framework. Microsoft's implementation of the CLI is called
the Common Language Runtime or CLR.
The Common Language Runtime consists of four major components:
Common Type System (CTS)
Defines how types are declared, used and managed in
the runtime.
Common Language Specification (CLS) A set of base rules to which any language should conform
in order to interoperate with other .NET languages
MetadataEmbedded data structures that describes the classes and
class members that are defined in within each assembly
Virtual Execution System
Gives an environment in which code can be executed
handling state, control flow and exception management.
CLR Infrastructure
ASSEMBLIES :- Portable Executable(PE) format
Assembly manifest.
Contains simple text name, Version No , public key token.
Metadata :-– Description of the assembly
– Self describing
– Metadata contains information about the assembly, and is also
used to implement the programming capabilities of .NET
Framework.
– CLR checks the metadata to ensure that the correct method
is called.
Security :- supported by the CLR is called Code Access Security (CAS).
Continue…. It is based on evidence that is associated with a specific
assembly.
– Code Access Security uses evidence to determine the
permissions granted to the code.
– If any assembly is not granted the permission a security
exception is thrown.
Just-In-Time (JIT) Compilation:-– At run time, the CLR uses JIT compilation to compile MSIL to
native machine code for the current platform.
– The CLR manages a pool of memory called the managed heap
– .NET continuously runs a Garbage Collector (GC)
BASE CLASS LIBRARIESNAMESPACE DESCRIPTION
System Provides base data types and almost 100
classes that deal with situations like exception
handling, mathematical functions, and garbage
collection.
System.CodeDom Provides the classes needed to produce source
files in all the .NET languages.
System.Collections Provides access to collection classes such as
lists,Queues, bit arrays, hash tables, and
dictionaries
System.Data Provides classes that allow data access and
manipulation to SQL Server and OLEDB data
sources.
System.Diagnostics Provides classes that allow you to debug
and trace Your application. There are
classes to interact with event logs,
performance counters, & system
processes.
System.Globalization Provides classes that access the global
system
variables, such as calendar display, date
and time settings, and currency display
settings.
System.IO Provides classes that allow access to file
and stream control and manipulation
System.Security Provides classes that allow access to
authentication,authorization, permissions,
and policies.
System.Text Provides classes for working with and
manipulating text strings.
GOALS OF .NET FRAMEWORK
• Based on Web standards and practices
• Extensible
• Easy for developers to use
VERSIONS OF .NET FRAMEWORK
Version Version Number Release Date Visual Studio Default in Windows
1.0 1.0.3705.0 2002-02-13 Visual Studio .NET
1.1 1.1.4322.573 2003-04-24 Visual Studio .NET 2003 Windows Server 2003
2.0 2.0.50727.42 2005-11-07 Visual Studio 2005 Windows Server 2003 R2
3.0 3.0.4506.30 2006-11-06Windows Vista, Windows
Server 2008
3.5 3.5.21022.8 2007-11-19 Visual Studio 2008Windows 7, Windows Server
2008 R2
4.0 4.0.30319.1 2010-04-12 Visual Studio 2010
Languages in the .NET Framework
LANGUAGE DESCRIPTION
Microsoft
Visual Basic .NET
Visual Basic .NET extension of Visual Basic. Visual Basic
.NET supports inheritance, constructors,
polymorphism, overloading, stricter type checking,
Microsoft Visual C#
C# is the first modern component-oriented language in
the C and C++ family. It can be embedded in ASP.NET
pages. Features of this language include classes,
interfaces, operator overloading,
Managed Extensions C++
The Visual C++ upgrade is a managed, minimal
extension to the C++ language. This extension include
garbage collection, single-implementation inheritance,
and multiple-interface inheritance.
Microsoft
Visual J# .NET
J# .NET is a language for Java-language developers who
want to build applications and services for the .NET
Framework. J# .NET is fully integrated with the Visual
Studio.NET IDE
Introduction to C#
WHAT IS C#
• C# (Pronounced as ‘C Sharp’) is a new programming language introduced by Microsoft.
• C# is fully object-oriented language like Java and is the first component-oriented language.
• C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++.
• C# is firmly planted in the C and C++ family tree of languages, and will immediately be familiar to C and C++ programmers.
WHAT IS C#
• C# is Specially designed to work with Microsoft’s .NET Platform.
• C# is designed for building robust , reliable , durable components to handle real- world applications.
• The name “C Sharp” was inspired by musical notation (#)whereas sharp indicates that the written note should be made a half-step higher in pitch.
This is similar to the language name of C++, where “++” indicate that a variable should be incremented by 1
Why C#...
• Not all of the supported languages fit entirely neatly into the .NET Framework, but the one language that is guaranteed to fit in perfectly is C#.
• C# is a successor to C++, has been released in conjunction with the .NET Framework.
• C# design goals:Be Comfortable for C++ Programmer.
Fit cleanly into the .NET Common Language Runtime(CLR)
Simplify the C++ model
Evolution Of C#
C
C++
Java C# VB
Productivity
Characteristics of C#
• Simple
• Consistent
• Modern
• Object-Oriented
• Type – Safe
• Versionable
• Flexible
C# Verses Java
• C# and Java are both languages descended from C and C++.
• Each includes advanced features like garbage collection, which remove some of the low level maintenance task from the programmer.
• Both C# and Java compile initially to an intermediate language:
a) C# to Microsoft Intermediate language(MSIL)
and Java to Java Byte code.
Types of applications developed with c#
• Web Applications
• Window Applications
• Console Applications
First c# program
using System;
class Hello
{
static void Main()
{
Console.WriteLine("Hello, C# world!");
}
}
Elements of c# program
Framework class Library
Namespace
Class
Method
Statement
Data types
C# Data Types
Value Types Reference Types
Predefined
TypesUser-defined
Types
Predefined
Types
User-defined
Types
User-Defined
Types
Predefined
Types
Value Types
Enumerations
Structures
Integer
Real
Boolean
Characters
User-Defined
Types
Predefined
Types
Reference Types
Classes
Arrays
Delegates
Interfaces
Objects
Strings
Boxing & Unboxing
• Boxing
The process of converting from a value type to a reference type is called boxing.
Boxing is an implicit conversion.
Boxing exampleusing System;class Conversion1{
static void Main(){
int num1 = 123;Object obj = num1;Console.WriteLine(num1.ToString());Console.WriteLine(obj.ToString());
}}
• Unboxing
The process of converting from a reference type to a value type is called unboxing.
Unboxing example
using System;
class Conversion1
{
static void Main()
{
Object obj = 123;
int num1 = (int)obj;
Console.WriteLine(num1.ToString());
Console.WriteLine(obj.ToString());
}}
Converting Between Numbers and Strings
• To make a string from a number or a number from a string, you can use the Convert methods.
string s = Convert.ToString (x);float y = Convert.ToSingle (s);
Note that “Single” means a single-precision floating point number.
• Numeric objects also provide various kinds of formatting options to specify the number of decimal places:
float x = 12.341514325f;string s =x.ToString ("###.###"); //gives
12.342
Loops and control structures
• The If Statement
• The Select Case Statement
• The Do While Loop
• The For Loop
The IF Statement
• The if . . .else statement is inherited from C and C++.• The if . . .else statement is also known as a conditional statement
Example:if (res > 25){res = res - 5;Console.WriteLine("Result is more then 25");}else{res = 25;Console.WriteLine("Result is less then 25");}
The Select Case statement
int i = 3;switch(i)
{case1:Console.WriteLine("one");break;case2:Console.WriteLine("two");break;case3:Console.WriteLine("three");break;default:Console.WriteLine("None of the about");break;
} In C# , you can use strings as well
While Loop & Do While Loop
• While Loop:
int i = 0;
while (i<10)
{
Console.WriteLine(i.ToString());
i++;
}
• Do While Loop:
int i = 0;
do
{
Console.WriteLine(i.ToString());
i++;
} while (i<10);
For Loops
for (int i=0; i<10; i++){Console.WriteLine(i.ToString( ) );}
For Each Loop:• The foreach loop enables you to iterate over each
element of an array or each element of a collection.
string[] strArr = {"Mahesh", "Chand", "Test String"};
foreach (string str in strArr)
Console.WriteLine(str);
Classes
In the C#, you define a class by using the class keyword, just as you do in C++. Following the class keyword the class name and curly brackets ({. . .}), as shown here:class Hello{
static void Main(){
Console.WriteLine("Hello, C# World!");}
}
Class Members
Class Members Inheritance
Methods Similar to C++ functions. Methods implement some action that can be performed by an object.
Properties Provide access to a class attribute (a field). Useful forexposing fields in components.
Events Used to provide notification.
Constants Represents a constant value.
Fields Represents a variable of the class
Operators Used to define an expression (+, *,->, ++,[], and so on )
Instance Constructors Methods called during initialization of an object.
Static Constructors Called automatically.
Destructors Called when an object is being destroyed.
Types All local types used in a class.
Class member accessibility types and scopes
ACCESSIBLITY TYPE SCOPE
Public Member is accessible from other programs.
Protected Member is accessible by the containing and its derived classes and types.
Internal Member is accessible only the current program.
Protected internal Member is accessible by the current program and the class derived from the containing class.
Methods
A method can return a value have, a list of parameters, and can be accessed through the class, whereas non - static. Static methods are accessed through the class, whereas non-static methods are accessed through the instance of the class.
Class method example
using System;class myClass{public int Sum(int a, int b){int res = a + b;return res;}}
class TestmyClass{static void Main(){myClass cls = new myClass();int total = cls.Sum(5, 8);Console.WriteLine(total.ToString());}}
Method Overloading
• Methods in C# support function overloading in a similar way as C++.
using System;
class myClass
{
public int Sum(int a, int b)
{
int r = a + b;
return r;
}
public float Sum(float a, float b)
{
float r = a + b;
return r;
}
public long Sum(long a, long b)
{
long r = a + b;
return r;
}
class TestClass
{
static void Main()
{
myClass cls = new myClass();
int t1 = cls.Sum(5,8);
Console.WriteLine("Return integer sum:“ +t1.ToString());
float t2 = cls.Sum(5.1,8.6);
Console.WriteLine("Return float sum:“ +t2.ToString());
}
}