Upload
dinhque
View
267
Download
0
Embed Size (px)
Citation preview
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET XML Web Services.NET XML Web Services
Alistair Lawson, SoC
Bill Buchanan, SoC
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Unit 5Unit 4: Web ServicesTuesday 26 JuneUnit 4Unit 4: Web ServicesTuesday 25 JuneUnit 3Unit 3: .NET RemotingTuesday 19 JuneUnit 3Unit 3: .NET RemotingTuesday 18 JuneUnit 2Unit 2: Manipulating XML DataTuesday 12 JuneUnit 2Unit 2: Manipulating XML DataTuesday 11 JuneUnit 1Unit 1: Creating/Manipulating DatasetsTuesday 5 June 2-4pmUnit 1Unit 1: Creating/Manipulating DatasetsTuesday 5 June 10-12-Unit 0: Introduction to .NETMonday 4 June 2-4pm-Unit 0: Introduction to .NETMonday 4 June 11-12
KalaniTitleDate
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Course Outline (Day 1 to 3)
• Day 1: Introduction to Object-Orientation, Introduction to .NET, Overview of .NET Framework, .NET Components. C#. Introduction to Visual Studio Environment.
.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Introduction
• Introduction to Object-orientation.• .NET Framework.• Visual Studio Environment.• Benefits of C# over VB.• .NET Components.• .NET Languages.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Introduction
Bill Buchanan
.NET Framework.NET Framework
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
So what’s wrong with the old model?
EXE ProgramEXE
Program
Lack of support for different hardwarePrograms were compiled to x86 code.
Weak integration with Internet/WWWCode and WWW code where seenas separate entities.
Lack of security IntegrationMost programs where written with little careabout security
Code.asp<%
val1 = 10val2 = 20result = Cstr(val1) + Cstr(val2)response.write "<BR>Value is " & resultresult = val1 + val2response.write "<BR>Value is " & result
%>
Code.asp<%
val1 = 10val2 = 20result = Cstr(val1) + Cstr(val2)response.write "<BR>Value is " & resultresult = val1 + val2response.write "<BR>Value is " & result
%>
Difficult to integratedifferent languages
Poor version control for system components
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
So what’s wrong with the old model?
EXE ProgramEXE
Program
Poor robustnessWhere applications often crash
Poor pre-run checkingThis is where applications often crashed on run-time
Difficult deployments
Lack of sharing between applications
Poor integration with differentdata sources, such as XML, databases,and text files.
Too much support for legacy code
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
API(Application
ProgrammingInterface)
API(Application
ProgrammingInterface)
COM+(Distributed
Components)
COM+(Distributed
Components)
ASPWWW
Services
ASPWWW
Services
.NET Platform
ExecutableProgram
ExecutableProgram
VB .NETVB .NET C#C#
Visual Studio
VBVB
ASPASPCC
C++C++
VBAVBA
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
What’s so special about .NET?
CTS (Common
TypeSystem)
CTS (Common
TypeSystem)
CLS(CommonLanguage
Specification)
CLS(CommonLanguage
Specification)
VB .NETVB .NETC#C#
CompilerCompiler
FCL(Framework
Class Library)
FCL(Framework
Class Library)
CLR (Common Language Runtime)Allows the programs to run – similar to the Java Virtual Machine (JVM)
CLR (Common Language Runtime)Allows the programs to run – similar to the Java Virtual Machine (JVM)
Webcomponent
Webcomponent
MSIL (Microsoft Intermediate Language)
MSIL (Microsoft Intermediate Language)
.NET Framework
J#J# Any?Any?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET Framework FilesVolume in drive C has no label.Volume Serial Number is 1A83-0D9D
Directory of C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
21/02/2003 08:24 7,680 Accessibility.dll21/02/2003 06:00 98,304 alink.dll20/02/2003 20:19 24,576 aspnet_filter.dll20/02/2003 20:19 253,952 aspnet_isapi.dll20/02/2003 20:19 40,960 aspnet_rc.dll20/02/2003 20:09 77,824 CORPerfMonExt.dll21/02/2003 11:21 626,688 cscomp.dll21/02/2003 08:24 12,288 cscompmgd.dll21/02/2003 08:24 33,792 CustomMarshalers.dll29/07/2002 12:11 219,136 c_g18030.dll21/02/2003 11:21 524,288 diasymreader.dll19/03/2003 02:52 245,760 envdte.dll20/02/2003 20:16 798,720 EventLogMessages.dll20/02/2003 20:06 282,624 fusion.dll21/02/2003 08:24 7,168 IEExecRemote.dll21/02/2003 08:24 32,768 IEHost.dll21/02/2003 08:24 4,608 IIEHost.dll21/02/2003 08:25 1,564,672 mscorcfg.dll20/02/2003 20:09 77,824 mscordbc.dll20/02/2003 20:09 233,472 mscordbi.dll20/02/2003 20:09 86,016 mscorie.dll20/02/2003 20:06 311,296 mscorjit.dll20/02/2003 20:09 98,304 mscorld.dll21/02/2003 08:26 2,088,960 mscorlib.dll20/02/2003 19:43 131,072 mscormmc.dll20/02/2003 20:06 65,536 mscorpe.dll20/02/2003 20:09 143,360 mscorrc.dll20/02/2003 20:09 81,920 mscorsec.dll20/02/2003 20:09 77,824 mscorsn.dll20/02/2003 20:07 2,494,464 mscorsvr.dll
Contains most of the codethat is called by the program
ProgramProgram
Mscorlib.dllArrays,File I/O,System,Security
Mscorlib.dllArrays,File I/O,System,Security
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET method of running applications
Application 1Application 2
Process 1
Process 2
.NET Framework
OperatingSystemProcessor
Memory
MSIL (Microsoft Intermediate Language)
MSIL (Microsoft Intermediate Language)
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET method of running applications
Application 1Application 2
Process 1
.NET FrameworkMSIL (Microsoft Intermediate Language
MSIL (Microsoft Intermediate Language)
Native codeNative code
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET method of running applications
Application 1Application 2
Process 1
.NET Framework
OperatingSystemProcessor
Memory
DLL 1.0
DLL 1.1
Global AssemblyCache
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Visual Studio Environment
Bill Buchanan
Visual Studio EnvironmentVisual Studio Environment
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
RequirementsAnalysis
RequirementsAnalysis
RequirementsSpecification
RequirementsSpecification DesignDesign
ImplementationImplementationTest/DebugTest/
DebugDeploymentDeployment
MaintenanceMaintenanceDecommissionDecommission
Refinement
Idea?Requirement?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Web Service
ASP.NET Web Page
Windows Application
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Mobile Application
Windows Service
Console Application
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Debug/Test
RequirementsAnalysis
RequirementsSpecification
Design
ImplementationTest/DebugDeployment
MaintenanceDecommission
Refinement
Idea?Requirement?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Deployment
Enhanced Deployment:-CAB files.-XCOPY deployment.-MSI Installation.-Web deployment.
RequirementsAnalysis
RequirementsSpecification
Design
ImplementationTest/DebugDeployment
MaintenanceDecommission
Refinement
Idea?Requirement?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Folder where the project is stored.
Name of the folderWhich contains the Project filesthe project is stored.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Class file (.cs)
Code and
Text Editor
Editor's statement
completion
Solution explorer
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Example of Auto-Complete
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Solution File (.sln)Module01_01.slnMicrosoft Visual Studio Solution File, Format Version 8.00Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Module01_01",
"Module01_01.csproj", "{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}"ProjectSection(ProjectDependencies) = postProjectEndProjectSection
EndProjectGlobal
GlobalSection(SolutionConfiguration) = preSolutionDebug = DebugRelease = Release
EndGlobalSectionGlobalSection(ProjectConfiguration) = postSolution
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Debug.ActiveCfg = Debug|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Debug.Build.0 = Debug|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Release.ActiveCfg = Release|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Release.Build.0 = Release|.NETEndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionEndGlobalSectionGlobalSection(ExtensibilityAddIns) = postSolutionEndGlobalSection
EndGlobal
Module01_01.slnMicrosoft Visual Studio Solution File, Format Version 8.00Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Module01_01",
"Module01_01.csproj", "{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}"ProjectSection(ProjectDependencies) = postProjectEndProjectSection
EndProjectGlobal
GlobalSection(SolutionConfiguration) = preSolutionDebug = DebugRelease = Release
EndGlobalSectionGlobalSection(ProjectConfiguration) = postSolution
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Debug.ActiveCfg = Debug|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Debug.Build.0 = Debug|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Release.ActiveCfg = Release|.NET
{1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3}.Release.Build.0 = Release|.NETEndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionEndGlobalSectionGlobalSection(ExtensibilityAddIns) = postSolutionEndGlobalSection
EndGlobal
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
CSProf fileModule01_01.csprof<VisualStudioProject>
<CSHARPProjectType = "Local"ProductVersion = "7.10.3077"SchemaVersion = "2.0"
><Build>
<SettingsApplicationIcon = "App.ico"AssemblyKeyContainerName = ""AssemblyName = "Module01_01"AssemblyOriginatorKeyFile = ""DefaultClientScript = "JScript"DefaultHTMLPageLayout = "Grid"DefaultTargetSchema = "IE50"DelaySign = "false" OutputType = "Exe"PreBuildEvent = "" PostBuildEvent = ""RootNamespace = "Module01_01"RunPostBuildEvent = "OnBuildSuccess“ ><Config
Name = "Debug"AllowUnsafeBlocks = "false"
../><Config
Name = "Release"AllowUnsafeBlocks = "false"BaseAddress = "285212672"
../>
</Settings><References>
</Build><Files>
<Include><File RelPath = "App.ico“ BuildAction = "Content" /><File RelPath = "AssemblyInfo.cs" SubType = "Code"
BuildAction = "Compile" /><File
RelPath = "Class1.cs" SubType = "Code"BuildAction = "Compile" />
</Include></Files>
</CSHARP></VisualStudioProject>
Module01_01.csprof<VisualStudioProject>
<CSHARPProjectType = "Local"ProductVersion = "7.10.3077"SchemaVersion = "2.0"
><Build>
<SettingsApplicationIcon = "App.ico"AssemblyKeyContainerName = ""AssemblyName = "Module01_01"AssemblyOriginatorKeyFile = ""DefaultClientScript = "JScript"DefaultHTMLPageLayout = "Grid"DefaultTargetSchema = "IE50"DelaySign = "false" OutputType = "Exe"PreBuildEvent = "" PostBuildEvent = ""RootNamespace = "Module01_01"RunPostBuildEvent = "OnBuildSuccess“ ><Config
Name = "Debug"AllowUnsafeBlocks = "false"
../><Config
Name = "Release"AllowUnsafeBlocks = "false"BaseAddress = "285212672"
../>
</Settings><References>
</Build><Files>
<Include><File RelPath = "App.ico“ BuildAction = "Content" /><File RelPath = "AssemblyInfo.cs" SubType = "Code"
BuildAction = "Compile" /><File
RelPath = "Class1.cs" SubType = "Code"BuildAction = "Compile" />
</Include></Files>
</CSHARP></VisualStudioProject>
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Solution File (.sln)
Class1.csusing System;
namespace Module01_01{
/// <summary>/// Summary description for Class1./// </summary>
class Class1{/// <summary>/// The main entry point for the application./// </summary>static void Main(string[] args){//// TODO: Add code to start application here
System.Console.WriteLine("AgilentCourse");System.Console.ReadLine();}
}}
Class1.csusing System;
namespace Module01_01{
/// <summary>/// Summary description for Class1./// </summary>
class Class1{/// <summary>/// The main entry point for the application./// </summary>static void Main(string[] args){//// TODO: Add code to start application here
System.Console.WriteLine("AgilentCourse");System.Console.ReadLine();}
}}
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
ICO file
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Visual Studio Environment
Simple Console ApplicationBill Buchanan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
using System;namespace ConsoleApplication1{class Class1{
static void Main(string[] args){
System.Console.WriteLine("This is my first program");System.Console.ReadLine();
}}
}
using System;namespace ConsoleApplication1{class Class1{
static void Main(string[] args){
System.Console.WriteLine("This is my first program");System.Console.ReadLine();
}}
}
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Tutorial Session 1:Q1.1 and Q1.2
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Introduction
An Introduction to Object-Orientation
Bill Buchanan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Some Cups
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
A Quick Introduction to Object-Orientation
Parameter Cup 1 Cup 2 Cup3Shape (Standard/Square/Mug) Standard Square MugColour (Red/Blue/Green) Blue Red GreenSize (Small/Medium/Large) Small Large SmallTransparency (0 to 100%) 100% 50% 25%Handle type (Small/Large) Small Small Large
In object-orientation:A collection of parameters defines a class.
Class for the cup is thus: Shape, Colour,Size, Transparency, HandleType.
In object-orientation: Objects arecreated from classes.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Example C# Program using Object-Orientationusing System;
namespace ConsoleApplication2{
public class Cup {
public string Shape;public string Colour;public string Size;public int Transparency;public string Handle;
public void DisplayCup(){
System.Console.WriteLine("Cup is {0}, {1}", Colour, Handle);}
}
class Class1{
static void Main(string[] args){
Cup cup = new Cup();cup.Colour = "Red";cup.Handle = "Small";cup.DisplayCup();System.Console.ReadLine();
}}
}
Class definitions
Available variables(properties)
Method
Create new objectSet propertiesApply method
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Another exampleusing System;
namespace ConsoleApplication2{
public class Circuit {
public double Parallel(double r1, double r2){
return((r1*r2)/(r1+r2));}public double Series(double r1, double r2){
return(r1+r2);}
}
class Class1{
static void Main(string[] args){
double v1=100,v2=100;double res;
Circuit cir = new Circuit();
res=cir.Parallel(v1,v2);System.Console.WriteLine("Parallel resistance is {0} ohms",res);
res=cir.Series(100,100);System.Console.WriteLine("Series resistance is {0} ohms",res);
System.Console.ReadLine();}
}}
Class definitions
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Another exampleusing System;namespace ConsoleApplication2{
public class Complex{
public double real;public double imag;
public double mag(){
return (Math.Sqrt(real*real+imag*imag));}public double angle(){
return (Math.Atan(imag/real)*180/Math.PI); }
}class Class1{
static void Main(string[] args){
string str;double mag,angle;Complex r = new Complex();
System.Console.Write("Enter real value >>");str=System.Console.ReadLine();r.real = Convert.ToInt32(str);
System.Console.Write("Enter imag value >>");str=System.Console.ReadLine();r.imag = Convert.ToInt32(str);
mag=r.mag();angle=r.angle();
System.Console.WriteLine("Mag is {0} and angle is {1}",mag,angle);System.Console.ReadLine();
}}
}
⎟⎠⎞
⎜⎝⎛=
+=
+=
−
xyz
yxz
yxz
1
22
tan
j
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Solution File (.sln) AssemblyInfo.csusing System.Reflection;using System.Runtime.CompilerServices;
//// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information// associated with an assembly.//[assembly: AssemblyTitle("")][assembly: AssemblyDescription("")][assembly: AssemblyConfiguration("")][assembly: AssemblyCompany("")][assembly: AssemblyProduct("")][assembly: AssemblyCopyright("")][assembly: AssemblyTrademark("")][assembly: AssemblyCulture("")]
//// Version information for an assembly consists of the following four values://// Major Version// Minor Version // Build Number// Revision//// You can specify all the values or you can default the Revision and Build
Numbers // by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyDelaySign(false)][assembly: AssemblyKeyFile("")][assembly: AssemblyKeyName("")]}
AssemblyInfo.csusing System.Reflection;using System.Runtime.CompilerServices;
//// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information// associated with an assembly.//[assembly: AssemblyTitle("")][assembly: AssemblyDescription("")][assembly: AssemblyConfiguration("")][assembly: AssemblyCompany("")][assembly: AssemblyProduct("")][assembly: AssemblyCopyright("")][assembly: AssemblyTrademark("")][assembly: AssemblyCulture("")]
//// Version information for an assembly consists of the following four values://// Major Version// Minor Version // Build Number// Revision//// You can specify all the values or you can default the Revision and Build
Numbers // by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyDelaySign(false)][assembly: AssemblyKeyFile("")][assembly: AssemblyKeyName("")]}
.NET uses assembly to represent a single unit. An assembly is a collection of files that appear as a single unit, such as a single DLL or an EXE.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Types
Types
Namespace: ConsoleAppplication2
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Members
Methods Variable
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Property
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Object Browser
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
System.Collections
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
.NET Languages
.NET LanguagesWhat are the languages?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Example of C# and VB.NET Code
‘ VB.NET Code Dim j As Integer
Dim prime As BooleanDim i As Integer
For i = 1 To 100prime = True
For j = 2 To (i / 2)If ((i Mod j) = 0) Then
prime = FalseEnd If
Next jIf (prime = True) Then
TextBox1.Text = TextBox1.Text & "," & Str(i)End If
Next i
‘ VB.NET Code Dim j As Integer
Dim prime As BooleanDim i As Integer
For i = 1 To 100prime = True
For j = 2 To (i / 2)If ((i Mod j) = 0) Then
prime = FalseEnd If
Next jIf (prime = True) Then
TextBox1.Text = TextBox1.Text & "," & Str(i)End If
Next i
// C# Codeint i, j;bool prime;
for (i=0;i<100;i++){
prime = true;
for (j=2;j<=i/2;j++){
if ((i%j)==0) prime=false;}if (prime==true) textBox1.Text+=" " + Convert.ToString(i);
}
// C# Codeint i, j;bool prime;
for (i=0;i<100;i++){
prime = true;
for (j=2;j<=i/2;j++){
if ((i%j)==0) prime=false;}if (prime==true) textBox1.Text+=" " + Convert.ToString(i);
}
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Example VB.NET CodePublic Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()MyBase.New()
End Sub'Form overrides dispose to clean up the component list.Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing ThenIf Not (components Is Nothing) Then
components.Dispose()End If
End IfMyBase.Dispose(disposing)
End Sub'Required by the Windows Form DesignerPrivate components As System.ComponentModel.IContainer
Friend WithEvents TextBox1 As System.Windows.Forms.TextBoxFriend WithEvents Button1 As System.Windows.Forms.Button<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBoxMe.Button1 = New System.Windows.Forms.ButtonMe.SuspendLayout()''TextBox1'Me.TextBox1.Location = New System.Drawing.Point(24, 16)Me.TextBox1.Multiline = TrueMe.TextBox1.Name = "TextBox1"Me.TextBox1.Size = New System.Drawing.Size(200, 168)Me.TextBox1.TabIndex = 0Me.TextBox1.Text = ""''Button1'Me.Button1.Location = New System.Drawing.Point(200, 192)Me.Button1.Name = "Button1"Me.Button1.Size = New System.Drawing.Size(80, 56)Me.Button1.TabIndex = 1Me.Button1.Text = "E&xit"''Form1'Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)Me.ClientSize = New System.Drawing.Size(292, 266)Me.Controls.Add(Me.Button1)Me.Controls.Add(Me.TextBox1)Me.Name = "Form1"Me.Text = "Form1"Me.ResumeLayout(False)
End Sub
#End Region
Public Class Form1Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()MyBase.New()
End Sub'Form overrides dispose to clean up the component list.Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing ThenIf Not (components Is Nothing) Then
components.Dispose()End If
End IfMyBase.Dispose(disposing)
End Sub'Required by the Windows Form DesignerPrivate components As System.ComponentModel.IContainer
Friend WithEvents TextBox1 As System.Windows.Forms.TextBoxFriend WithEvents Button1 As System.Windows.Forms.Button<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBoxMe.Button1 = New System.Windows.Forms.ButtonMe.SuspendLayout()''TextBox1'Me.TextBox1.Location = New System.Drawing.Point(24, 16)Me.TextBox1.Multiline = TrueMe.TextBox1.Name = "TextBox1"Me.TextBox1.Size = New System.Drawing.Size(200, 168)Me.TextBox1.TabIndex = 0Me.TextBox1.Text = ""''Button1'Me.Button1.Location = New System.Drawing.Point(200, 192)Me.Button1.Name = "Button1"Me.Button1.Size = New System.Drawing.Size(80, 56)Me.Button1.TabIndex = 1Me.Button1.Text = "E&xit"''Form1'Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)Me.ClientSize = New System.Drawing.Size(292, 266)Me.Controls.Add(Me.Button1)Me.Controls.Add(Me.TextBox1)Me.Name = "Form1"Me.Text = "Form1"Me.ResumeLayout(False)
End Sub
#End Region
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j As IntegerDim prime As BooleanDim i As Integer
For i = 1 To 100prime = True
For j = 2 To (i / 2)If ((i Mod j) = 0) Then
prime = FalseEnd If
Next jIf (prime = True) Then
TextBox1.Text = TextBox1.Text & "," & Str(i)End If
Next i
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Application.Exit()End Sub
End Class
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Example C# codeusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;
namespace WindowsApplication1{
public class Form1 : System.Windows.Forms.Form{
private System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.Button button1;/// <summary>/// Required designer variable./// </summary>private System.ComponentModel.Container components = null;
public Form1(){
InitializeComponent();
}
protected override void Dispose( bool disposing ){
if( disposing ){
if (components != null) {
components.Dispose();}
}base.Dispose( disposing );
}
#region Windows Form Designer generated codeprivate void InitializeComponent(){
this.textBox1 = new System.Windows.Forms.TextBox();this.button1 = new System.Windows.Forms.Button();this.SuspendLayout();// // textBox1// this.textBox1.Location = new System.Drawing.Point(24, 16);this.textBox1.Multiline = true;this.textBox1.Name = "textBox1";this.textBox1.Size = new System.Drawing.Size(184, 152);this.textBox1.TabIndex = 0;this.textBox1.Text = "";// // button1// this.button1.Location = new System.Drawing.Point(200, 208);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(72, 48);this.button1.TabIndex = 1;this.button1.Text = "E&xit";this.button1.Click += new System.EventHandler(this.button1_Click);//
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;
namespace WindowsApplication1{
public class Form1 : System.Windows.Forms.Form{
private System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.Button button1;/// <summary>/// Required designer variable./// </summary>private System.ComponentModel.Container components = null;
public Form1(){
InitializeComponent();
}
protected override void Dispose( bool disposing ){
if( disposing ){
if (components != null) {
components.Dispose();}
}base.Dispose( disposing );
}
#region Windows Form Designer generated codeprivate void InitializeComponent(){
this.textBox1 = new System.Windows.Forms.TextBox();this.button1 = new System.Windows.Forms.Button();this.SuspendLayout();// // textBox1// this.textBox1.Location = new System.Drawing.Point(24, 16);this.textBox1.Multiline = true;this.textBox1.Name = "textBox1";this.textBox1.Size = new System.Drawing.Size(184, 152);this.textBox1.TabIndex = 0;this.textBox1.Text = "";// // button1// this.button1.Location = new System.Drawing.Point(200, 208);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(72, 48);this.button1.TabIndex = 1;this.button1.Text = "E&xit";this.button1.Click += new System.EventHandler(this.button1_Click);//
// Form1// this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);this.ClientSize = new System.Drawing.Size(292, 266);this.Controls.Add(this.button1);this.Controls.Add(this.textBox1);this.Name = "Form1";this.Text = "Form1";this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);
}#endregion/// </summary>[STAThread]static void Main() {
Application.Run(new Form1());}
private void Form1_Load(object sender, System.EventArgs e){
int i, j;bool prime;
for (i=0;i<100;i++){
prime = true;for (j=2;j<=i/2;j++){
if ((i%j)==0) prime=false;}if (prime==true) textBox1.Text+=" " + Convert.ToString(i);
}
}
private void button1_Click(object sender, System.EventArgs e){
Application.Exit();}
}}
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Why?
BenefitsWhy C#?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
C Programming … to …
#include <stdio.h>#include <math.h>int main(void){float a,b,c,real1,real2,imag;
puts("Program to determine roots of a quadratic equation");printf("Enter a,b and c >>>");scanf("%f %f %f",&a,&b,&c);printf("Equation is %.2fx*x + %.2fx + %.2f\n",a,b,c);if ((b*b)==(4*a*c)) { real1=-b/(2*a);
printf("Root is %.2f\n",real1);} else if ((b*b)>(4*a*c)) {
real1=(-b+sqrt( (b*b)-4*a*c )) /(2*a);real2=(-b-sqrt( (b*b)-4*a*c )) /(2*a);printf("Roots are %.2f, %.2f\n",real1,real2);
} else
{real1=-b/(2*a);imag=sqrt(4*a*c-b*b)/(2*a);printf("Roots are %.2f +/- j%.2f\n",real1,imag);
}return(0);
}
#include <stdio.h>#include <math.h>int main(void){float a,b,c,real1,real2,imag;
puts("Program to determine roots of a quadratic equation");printf("Enter a,b and c >>>");scanf("%f %f %f",&a,&b,&c);printf("Equation is %.2fx*x + %.2fx + %.2f\n",a,b,c);if ((b*b)==(4*a*c)) { real1=-b/(2*a);
printf("Root is %.2f\n",real1);} else if ((b*b)>(4*a*c)) {
real1=(-b+sqrt( (b*b)-4*a*c )) /(2*a);real2=(-b-sqrt( (b*b)-4*a*c )) /(2*a);printf("Roots are %.2f, %.2f\n",real1,real2);
} else
{real1=-b/(2*a);imag=sqrt(4*a*c-b*b)/(2*a);printf("Roots are %.2f +/- j%.2f\n",real1,imag);
}return(0);
}
Advantages:-Minimal language.-Standardized.-Flexible.
Disadvantages:-Weak checking for errors.-Focused on proceduresrather than data.
-Lack of support for graphics(such as Windows).
Advantages:-Minimal language.-Standardized.-Flexible.
Disadvantages:-Weak checking for errors.-Focused on proceduresrather than data.
-Lack of support for graphics(such as Windows).
CLanguage
CLanguage
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
C Programming … to …C
Language
#include <iostream.h>class circuit{private:
float rtemp;public:
float parallel(float r1, float r2){
return((r1*r2)/(r1+r2));}float series(float r1, float r2){
return(r1+r2);}
};int main(void){circuit c1;float res;
res=c1.series(2000,1000);cout << "Series resistance is " << res << "ohms\n";res=c1.parallel(1000,1000);cout << "Parallel resistance is " << res << "ohms\n";return(0);
}
#include <iostream.h>class circuit{private:
float rtemp;public:
float parallel(float r1, float r2){
return((r1*r2)/(r1+r2));}float series(float r1, float r2){
return(r1+r2);}
};int main(void){circuit c1;float res;
res=c1.series(2000,1000);cout << "Series resistance is " << res << "ohms\n";res=c1.parallel(1000,1000);cout << "Parallel resistance is " << res << "ohms\n";return(0);
}
Advantages:-Standardized.-Flexible.-Object-oriented.-Improved error checking.-Improved Windows support
Disadvantages:-Still a hybrid language (C and/or C++).-Still too generic.-Lack of integration withother languages.
Advantages:-Standardized.-Flexible.-Object-oriented.-Improved error checking.-Improved Windows support
Disadvantages:-Still a hybrid language (C and/or C++).-Still too generic.-Lack of integration withother languages.
C++Language
C++Language
Object-orientation added
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
C++Language
C Programming … to …C
Language
using System;
namespace ConsoleApplication2{
public class Circuit {public double Parallel(double r1, double r2){
return((r1*r2)/(r1+r2));}public double Series(double r1, double r2){
return(r1+r2);}}class Class1{static void Main(string[] args){double v1=100,v2=100;double res;
Circuit cir = new Circuit();res=cir.Parallel(v1,v2);System.Console.WriteLine("Parallel resistance is {0} ohms",res);res=cir.Series(100,100);System.Console.WriteLine("Series resistance is {0} ohms",res);System.Console.ReadLine();
}}
using System;
namespace ConsoleApplication2{
public class Circuit {public double Parallel(double r1, double r2){
return((r1*r2)/(r1+r2));}public double Series(double r1, double r2){
return(r1+r2);}}class Class1{static void Main(string[] args){double v1=100,v2=100;double res;
Circuit cir = new Circuit();res=cir.Parallel(v1,v2);System.Console.WriteLine("Parallel resistance is {0} ohms",res);res=cir.Series(100,100);System.Console.WriteLine("Series resistance is {0} ohms",res);System.Console.ReadLine();
}}
Advantages:-Fully object-oriented.-Robust.-Integrated with Windows.-Cross-platform.-Support for mobility.-Strong integration with
Disadvantages:-Massive programmingenvironment.
Advantages:-Fully object-oriented.-Robust.-Integrated with Windows.-Cross-platform.-Support for mobility.-Strong integration with
Disadvantages:-Massive programmingenvironment.
C#Language
C#Language
Windows/WWW/Java ideas
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Why C#?The gap between C and VB is now closed as both provide an excellent environment for software development.
VB.NET is aimed at Microsoft Office and WWW-based Applications, as it integrates well with VBA and ASP. VB has traditionally supported unstructured code, but this has now changed.
C# is aimed at engineering applications, and allows for more flexibility, such as using pointers. There is also a great amount of code developed for many different applications, such as DSP, interfacing, and so on.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Why?
Elements of a C# ProgramWhat goes where?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
C# Program Outlineusing System;namespace ConsoleApplication2{
public class Complex{
public double real;public double imag;public int val { set {} get {} };public double mag(){
return (Math.Sqrt(real*real+imag*imag));}public double angle(){
return (Math.Atan(imag/real)*180/Math.PI); }
}class Class1{
static void Main(string[] args){
Complex r = new Complex();string str;double mag,angle;
System.Console.Write("Enter real value >> ");str=System.Console.ReadLine();r.real = Convert.ToInt32(str);System.Console.Write("Enter imag value >> ");str=System.Console.ReadLine();r.imag = Convert.ToInt32(str);mag=r.mag();angle=r.angle();System.Console.WriteLine("Mag is {0} and angle is {1}",mag,angle);System.Console.ReadLine();
}}
}
Main(). This is the entry point into the program, and defines the start and end of the program. It must be declared inside a class, and must be static.
Main(). This is the entry point into the program, and defines the start and end of the program. It must be declared inside a class, and must be static.
using. Imports types defined in other namespaces.
using. Imports types defined in other namespaces.
namespace. Defines a uniquename for the objects. In this case the objects would have the name of:ConsoleApplications2.Complex()ConsoleApplicaitons2.Class1()
namespace. Defines a uniquename for the objects. In this case the objects would have the name of:ConsoleApplications2.Complex()ConsoleApplicaitons2.Class1()
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
C# Program Outlineusing System;namespace ConsoleApplication2{
public class Complex{
public double real;public double imag;public int val { set {} get {} };public double mag(){
return (Math.Sqrt(real*real+imag*imag));}public double angle(){
return (Math.Atan(imag/real)*180/Math.PI); }
}class Class1{
static void Main(string[] args){
Complex r = new ConsoleApplication2.Complex();string str;double mag,angle;
System.Console.Write("Enter real value >> ");str=System.Console.ReadLine();r.real = Convert.ToInt32(str);System.Console.Write("Enter imag value >> ");str=System.Console.ReadLine();r.imag = Convert.ToInt32(str);mag=r.mag();angle=r.angle();System.Console.WriteLine("Mag is {0} and angle is {1}",mag,angle);System.Console.ReadLine();
}}
}
namespace. Defines a uniquename for the objects. In this case the objects would have the name of:ConsoleApplications2.Complex()ConsoleApplicaitons2.Class1()
namespace. Defines a uniquename for the objects. In this case the objects would have the name of:ConsoleApplications2.Complex()ConsoleApplicaitons2.Class1()
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
System.Console.System.Console.Write("Enter real value >> ");
using. Imports types defined in other namespaces.
using. Imports types defined in other namespaces.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
System.Math.Math.Sqrt(real*real+imag*imag)
using. Imports types defined in other namespaces.
using. Imports types defined in other namespaces.
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Typical namespaces
System: Array, Boolean, Byte, Char, Convert, DateTime, Double, Enum, Int16, Int32, Int 64, Math, Random, String, VoidSystem.Collections:ArrayList, BitArray, Hashtable, Queue, Stack.System.IO:BinaryReader, BinaryWriter, File, Stream, StreamWriter, StreamReader
uses System;uses System.Collections;uses System.IO
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Why?
.NET ComponentsWhat are components?
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Components
MS Outlookcomponent
MS Outlookcomponent
MS IEcomponent
MS IEcomponent
MS WordcomponentMS Word
component
Application uses componentsto gain access to services
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
TM Developer Components
Application uses componentsto gain access to services
Aut
hor:
Bill
Buch
anan
Aut
hor:
Bill
Buch
anan
Tutorial Session 2:Q1.3 and on