Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Similar documents
Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

.NET XML Web Services

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

6: Arrays and Collections

6: Arrays and Collections

.NET. Details: Name: Course:.Net XML Web Services Introduction to.net Unit: 0 Instructors: Bill Buchanan/ Alistair Lawson. W.Buchanan/A.

User-Defined Controls

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

Module 5: Review of Day 3

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

Module 5: Review of Day 3

This is the start of the server code

Tutorial 5 Completing the Inventory Application Introducing Programming

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0];

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

2. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. both (a) and (b) D. stands for Graphic Use Interaction

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

DAD Lab. 1 Introduc7on to C#

C# and.net (1) cont d

.Net Technologies. Components of.net Framework

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN

CHAPTER 3. Writing Windows C# Programs. Objects in C#

PES INSTITUTE OF TECHNOLOGY

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

Avoiding KeyStrokes in Windows Applications using C#

Inheriting Windows Forms with Visual C#.NET

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Web Services in.net (2)

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Flag Quiz Application

Introduction to Programming Using Java (98-388)

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Very similar to Java C++ C-Based syntax (if, while, ) object base class no pointers, object parameters are references All code in classes

Short Notes of CS201

PS2 Random Walk Simulator

The Microsoft.NET Framework

CS201 - Introduction to Programming Glossary By

BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How

.NET XML Web Services

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank

Module 4: Data Types and Variables

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent()

Department of Computer Applications

Darshan Institute of Engineering & Technology for Diploma Studies

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java.

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

6.096 Introduction to C++ January (IAP) 2009

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

UNIT III APPLICATION DEVELOPMENT ON.NET

ALPHAPRIMETECH 112 New South Road, Hicksville, NY 11801

DOT NET Syllabus (6 Months)

Learning to Program in Visual Basic 2005 Table of Contents

Apex TG India Pvt. Ltd.

.Net. Course Content ASP.NET

Introduction to Managed Code

Lampiran B. Program pengendali

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Objectives. After completing this topic, the students will: Understand of the concept of polymorphism Know on How to implement 2 types of polymorphism

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

You can call the project anything you like I will be calling this one project slide show.

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Last Time. Arrays. Arrays. Jagged Arrays. foreach. We began looking at GUI Programming Completed talking about exception handling

Chapter 1 Getting Started

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Absolute C++ Walter Savitch

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types

Programming with Microsoft Visual Basic.NET. Array. What have we learnt in last lesson? What is Array?

Model Question Paper. Credits: 4 Marks: 140. Part A (One mark questions)

C#: framework overview and in-the-small features

Introduce C# as Object Oriented programming language. Explain, tokens,

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

CS708 Lecture Notes. Visual Basic.NET Object-Oriented Programming. Implementing Client/Server Architectures. Part (I of?) (Lecture Notes 5A)

Chapter 12 Microsoft Assemblies. Software Architecture Microsoft Assemblies 1

Unit 1: Visual Basic.NET and the.net Framework

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS201 Latest Solved MCQs

In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result.

Professional ASP.NET Web Services : Asynchronous Programming

C# Syllabus. MS.NET Framework Introduction

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Dot Net Online Training

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Index COPYRIGHTED MATERIAL

Lab - 1. Solution : 1. // Building a Simple Console Application. class HelloCsharp. static void Main() System.Console.WriteLine ("Hello from C#.

CHAPTER 1: INTRODUCTION TO THE IDE 3

DOT NET SYLLABUS FOR 6 MONTHS

TECHNOLOGIES. Kick Starting OOPS &.Net Encapsulation Ø Class Ø Struct Ø Interface, Ø Enum Ø Abstraction Ø Access modifiers in.net

Transcription:

Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1)

Course Outline Day 1: Morning Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Day 1: Afternoon Data Types, Variables, Converting Data Types, if, for, while, File Handling Day 2: Morning Arrays, System.Collections, ArrayLists, Hashtables. Day 2: Afternoon Reference-Type Variables, Common Reference Types, Object Hierarchy, Namespaces, Debugging. Day 3: Morning Methods, Exceptions, Namespaces, Modules/ Assemblies, Non-visual Components, Regular Expressions, Intellisense, Help, Delegates, Events. Day 3: Afternoon Cerebus, Limit-check components, Power meter class. Course Outline (Day 1 to 3) W.Buchanan (2)

Course Outline Day 4: Morning Classes, Encapsulation, Object-Orientation, Classes, Sealed Classes, Interfaces, Abstract Classes. Day 4: Afternoon Using Constructors, Initializing Memory, Objects and Memory, Resource Management. Day 5: Morning Cerebus: 1mW Test. Day 5: Afternoon Operators, Operator Overloading, Attributes, Custom Attributes, Retrieving Attribute Values. Course Outline (Day 4 and 5) W.Buchanan (3)

Module 1 Introduction to Object-orientation..NET Framework. Visual Studio Environment. Benefits of C# over VB..NET Components..NET Languages. Introduction W.Buchanan (4)

An Introduction to Object- Orientation Bill Buchanan Introduction W.Buchanan (5)

Some Cups W.Buchanan (6)

Parameter Cup 1 Cup 2 Cup3 Shape (Standard/Square/Mug) Standard Square Mug Colour (Red/Blue/Green) Blue Red Green Size (Small/Medium/Large) Small Large Small Transparency (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 are created from classes. A Quick Introduction to Object-Orientation W.Buchanan (7)

using System; namespace ConsoleApplication2 Class definitions public class Cup public string Shape; public string Colour; public string Size; public int Transparency; public string Handle; Available variables (properties) Method 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(); Create new object Set properties Apply method Example C# Program using Object-Orientation W.Buchanan (8)

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 definitions 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(); Another example W.Buchanan (9)

using 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(); z = x + jy z z = x 2 = tan + y 1 2 y x Another example W.Buchanan (10)

.NET Framework Bill Buchanan Introduction W.Buchanan (11)

Source Code (C/C++/ Delphi/ VB) Compilation OBJ file Linker Linker EXE EXE Program Program Static Static Libraries gdi32.dll API (Application Programming Interface) ole32.dll Traditional Windows Model W.Buchanan (12)

Creating windows. Windows support functions. Message processing. Menus. Resources. Dialog boxes. User input functions. Memory management. GDI (graphical device interface). Bitmaps, icons and metafiles. Printing and text output. Painting and drawing. File I/O. Clipboard. Support for public and private clipboards. Registry. Support for functions which access the Registry. Initialization files. Support for functions which access INI files. System information. String manipulation. Timers. Processes and threads. Example Error and exception processing. Example C++ C++ code code calling calling an an API API #include <windows.h> #include <windows.h> MDI (multiple document int interface). WINAPI WinMain(HINSTANCE hinstance, int WINAPI WinMain(HINSTANCE hinstance, Help files. HINSTANCE hprev, LPSTR lpcmd, int nshow) HINSTANCE hprev, LPSTR lpcmd, int nshow) File compression/decompression. char msg[128]; DLLs. char msg[128]; wsprintf(msg, "My name is Fred"); Network support (NetBios and wsprintf(msg, Windows sockets "My name 1.1 APIs). is Fred"); MessageBox(GetFocus(), msg, "My first MessageBox(GetFocus(), msg, "My first Multimedia support (sound Window", APIs). MB_OK MB_ICONINFORMATION); Window", MB_OK MB_ICONINFORMATION); OLE and DDE (dynamic data return(0); return(0); exchange). TrueType fonts. gdi32.dll EXE EXE Program Program API (Application Programming Interface) ole32.dll Traditional Windows Model W.Buchanan (13)

EXE EXE Program Program Lack of support for different hardware Programs were compiled to x86 code. Difficult to integrate different languages Lack of security Integration Most programs where written with little care about security Poor version control for system components Weak integration with Internet/WWW Code and WWW code where seen as separate entities. Code.asp Code.asp <% <% %> %> val1 = 10 val1 = 10 val2 = 20 val2 = 20 result = Cstr(val1) + Cstr(val2) result = Cstr(val1) + Cstr(val2) response.write "<BR>Value is " & result response.write "<BR>Value is " & result result = val1 + val2 result = val1 + val2 response.write "<BR>Value is " & result response.write "<BR>Value is " & result So what s wrong with the old model? W.Buchanan (14)

VB VB ASP ASP ASP ASP VB VB.NET.NET C# C# C C C++ C++ VBA VBA Executable Executable Program Program Visual Studio ASP WWW Services COM+ (Distributed Components).NET Platform API (Application Programming Interface) New.NET Platform W.Buchanan (15)

VB VB.NET.NET C# C# FCL FCL (Framework Class Class Library) Web Web component component Compiler CLS CLS (Common (Common Language Language Specification) Specification) CTS CTS (Common (Common Type Type System) System) MSIL (Microsoft Intermediate Language) CLR CLR (Common Language Runtime) Allows Allows the the programs to to run run similar similar to to the the Java Java Virtual Virtual Machine (JVM) (JVM) How are languages integrated? W.Buchanan (16)

Volume 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.dll 21/02/2003 06:00 98,304 alink.dll 20/02/2003 20:19 24,576 aspnet_filter.dll 20/02/2003 20:19 253,952 aspnet_isapi.dll 20/02/2003 20:19 40,960 aspnet_rc.dll 20/02/2003 20:09 77,824 CORPerfMonExt.dll 21/02/2003 11:21 626,688 cscomp.dll 21/02/2003 08:24 12,288 cscompmgd.dll 21/02/2003 08:24 33,792 CustomMarshalers.dll 29/07/2002 12:11 219,136 c_g18030.dll 21/02/2003 11:21 524,288 diasymreader.dll 19/03/2003 02:52 245,760 envdte.dll 20/02/2003 20:16 798,720 EventLogMessages.dll 20/02/2003 20:06 282,624 fusion.dll 21/02/2003 08:24 7,168 IEExecRemote.dll 21/02/2003 08:24 32,768 IEHost.dll 21/02/2003 08:24 4,608 IIEHost.dll 21/02/2003 08:25 1,564,672 mscorcfg.dll 20/02/2003 20:09 77,824 mscordbc.dll 20/02/2003 20:09 233,472 mscordbi.dll 20/02/2003 20:09 86,016 mscorie.dll 20/02/2003 20:06 311,296 mscorjit.dll 20/02/2003 20:09 98,304 mscorld.dll 21/02/2003 08:26 2,088,960 mscorlib.dll 20/02/2003 19:43 131,072 mscormmc.dll 20/02/2003 20:06 65,536 mscorpe.dll 20/02/2003 20:09 143,360 mscorrc.dll 20/02/2003 20:09 81,920 mscorsec.dll 20/02/2003 20:09 77,824 mscorsn.dll 20/02/2003 20:07 2,494,464 mscorsvr.dll 20/02/2003 20:09 9,216 mscortim.dll 20/02/2003 20:08 2,482,176 mscorwks.dll 21/02/2003 05:42 348,160 msvcr71.dll 18/03/2003 20:03 544,768 msvcr71d.dll 20/02/2003 20:18 20,480 mtxoci8.dll 19/03/2003 02:50 196,608 office.dll 20/02/2003 20:09 90,112 PerfCounter.dll 21/02/2003 08:26 32,768 RegCode.dll Program Contains most of the code that is called by the program Mscorlib.dll Arrays, Arrays, File File I/O, I/O, System, System, Security Security.NET Framework Files W.Buchanan (17)

Visual Studio Environment Bill Buchanan Visual Studio Environment W.Buchanan (18)

Name of the folder Which contains the Project files the project is stored. Folder where the project is stored. W.Buchanan (19)

Class file (.cs) Solution explorer Code and Text Editor Editor's statement completion W.Buchanan (20)

Example of Auto-Complete W.Buchanan (21)

W.Buchanan (22)

Module01_01.sln Module01_01.sln Microsoft Visual Studio Solution File, Format Version 8.00 Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") Microsoft Visual Studio Solution File, Format Version = "Module01_01", 8.00 Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") "Module01_01.csproj", "1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3" = "Module01_01", ProjectSection(ProjectDependencies) "Module01_01.csproj", "1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3" = postproject EndProjectSection ProjectSection(ProjectDependencies) = postproject EndProject EndProjectSection Global EndProject Global GlobalSection(SolutionConfiguration) = presolution GlobalSection(SolutionConfiguration) Debug = Debug = presolution Release Debug = = Debug Release EndGlobalSection Release = Release GlobalSection(ProjectConfiguration) EndGlobalSection = postsolution GlobalSection(ProjectConfiguration) 1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3.Debug.ActiveCfg = postsolution = Debug.NET 1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3.Debug.ActiveCfg = Debug.NET 1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3.Debug.Build.0 = 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.ActiveCfg = Release.NET 1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3.Release.Build.0 = Release.NET 1EA384DD-927E-4B94-ABB8-BA08DFAE5AB3.Release.Build.0 = EndGlobalSection Release.NET GlobalSection(ExtensibilityGlobals) EndGlobalSection = postsolution EndGlobalSection GlobalSection(ExtensibilityGlobals) = postsolution GlobalSection(ExtensibilityAddIns) EndGlobalSection = postsolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postsolution EndGlobal EndGlobalSection EndGlobal Solution File (.sln) W.Buchanan (23)

CSProf file Module01_01.csprof Module01_01.csprof <VisualStudioProject> <VisualStudioProject> <CSHARP <CSHARP ProjectType = "Local" ProductVersion ProjectType = = "Local" "7.10.3077" SchemaVersion ProductVersion = "2.0" = "7.10.3077" > SchemaVersion = "2.0" > <Build> <Build> <Settings <Settings ApplicationIcon = "App.ico" AssemblyKeyContainerName ApplicationIcon = "App.ico" = "" AssemblyName AssemblyKeyContainerName = "Module01_01" = "" AssemblyOriginatorKeyFile AssemblyName = "Module01_01" = "" DefaultClientScript AssemblyOriginatorKeyFile = "JScript" = "" DefaultHTMLPageLayout DefaultClientScript = = "JScript" "Grid" DefaultTargetSchema DefaultHTMLPageLayout = "IE50" = "Grid" DelaySign DefaultTargetSchema = "false" = "IE50" OutputType = "Exe" PreBuildEvent DelaySign = "false" = "" PostBuildEvent OutputType = = "Exe" "" RootNamespace PreBuildEvent = = "Module01_01" "" PostBuildEvent = "" RunPostBuildEvent RootNamespace = "Module01_01" = "OnBuildSuccess > <Config RunPostBuildEvent = "OnBuildSuccess > <Config Name = "Debug" AllowUnsafeBlocks Name = "Debug" = "false".. AllowUnsafeBlocks = "false".. /> <Config /> <Config Name = "Release" AllowUnsafeBlocks Name = "Release" = "false" BaseAddress AllowUnsafeBlocks = "285212672" = "false".. BaseAddress = "285212672".. /> </Settings> /> <References> </Settings> </Build> <References> <Files> </Build> <Files> <Include> <Include> <File RelPath = "App.ico BuildAction = "Content" /> <File <File RelPath RelPath = = "App.ico "AssemblyInfo.cs" BuildAction SubType = "Content" = "Code" /> <File BuildAction RelPath = = "Compile" "AssemblyInfo.cs" /> SubType = "Code" <File BuildAction = "Compile" /> <File RelPath = "Class1.cs" SubType = "Code" BuildAction RelPath = "Class1.cs" = "Compile" SubType = "Code" /> </Include> BuildAction = "Compile" /> </Files> </Include> </CSHARP> </Files> </VisualStudioProject> </CSHARP> </VisualStudioProject> W.Buchanan (24)

Class1.cs Class1.cs using System; using System; namespace Module01_01 namespace Module01_01 /// <summary> /// <summary> /// Summary description for Class1. /// Summary description for Class1. /// </summary> /// </summary> class Class1 class Class1 /// <summary> /// <summary> /// The main entry point for the application. /// The main entry point for the application. /// </summary> /// </summary> static void Main(string[] args) static void Main(string[] args) // // // TODO: Add code to start application here // TODO: Add code to start application here System.Console.WriteLine("Agilent System.Console.WriteLine("Agilent Course"); Course"); System.Console.ReadLine(); System.Console.ReadLine(); Solution File (.sln) W.Buchanan (25)

ICO file W.Buchanan (26)

.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. AssemblyInfo.cs AssemblyInfo.cs using System.Reflection; using using System.Runtime.CompilerServices; System.Reflection; using System.Runtime.CompilerServices; // // // General Information about an assembly is controlled through the following // // set General of attributes. Information Change about these an assembly attribute is values controlled to modify through the the information following // // associated set of attributes. with an assembly. Change these attribute values to modify the information // // associated with an assembly. [assembly: // AssemblyTitle("")] [assembly: [assembly: AssemblyDescription("")] AssemblyTitle("")] [assembly: [assembly: AssemblyConfiguration("")] AssemblyDescription("")] [assembly: [assembly: AssemblyCompany("")] AssemblyConfiguration("")] [assembly: [assembly: AssemblyProduct("")] AssemblyCompany("")] [assembly: [assembly: AssemblyCopyright("")] AssemblyProduct("")] [assembly: [assembly: AssemblyTrademark("")] AssemblyCopyright("")] [assembly: [assembly: AssemblyCulture("")] AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // // Version information for an assembly consists of the following four values: // // Version information for an assembly consists of the following four values: // // Major Version // // Minor Major Version Version // // Build Minor Number Version // // Revision Build Number // // Revision // // You can specify all the values or you can default the Revision and Build // You Numbers can specify all the values or you can default the Revision and Build // by using Numbers the '*' as shown below: // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] [assembly: [assembly: AssemblyKeyFile("")] AssemblyDelaySign(false)] [assembly: [assembly: AssemblyKeyName("")] AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] Solution File (.sln) W.Buchanan (27)

Types Namespace: ConsoleAppplication2 Types W.Buchanan (28)

Methods Variable Members W.Buchanan (29)

Property W.Buchanan (30)

Object Browser W.Buchanan (31)

System.Collections W.Buchanan (32)

.NET Languages What are the languages?.net Languages W.Buchanan (33)

VB.NET Code VB.NET Code Dim j As Integer Dim j As Integer Dim prime As Boolean Dim prime As Boolean Dim i As Integer Dim i As Integer For i = 1 To 100 For i = 1 To 100 prime = True prime = True For j = 2 To (i / 2) For j = 2 To (i / 2) If ((i Mod j) = 0) Then If ((i Mod j) = 0) Then prime = False prime = False End If End If Next j Next j If (prime = True) Then If (prime = True) Then TextBox1.Text = TextBox1.Text & "," & Str(i) TextBox1.Text = TextBox1.Text & "," & Str(i) End If End If Next i Next i // C# Code // C# Code int i, j; int i, j; bool prime; bool prime; for (i=0;i<100;i++) for (i=0;i<100;i++) prime = true; prime = true; for (j=2;j<=i/2;j++) for (j=2;j<=i/2;j++) if ((i%j)==0) prime=false; if ((i%j)==0) prime=false; if (prime==true) textbox1.text+=" " + Convert.ToString(i); if (prime==true) textbox1.text+=" " + Convert.ToString(i); Example of C# and VB.NET Code W.Buchanan (34)

Public Class Form1 Public Inherits Class System.Windows.Forms.Form Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " #Region " Windows Form Designer generated code " Public Sub New() Public MyBase.New() Sub New() MyBase.New() End Sub 'Form End Sub overrides dispose to clean up the component list. Protected 'Form overrides Overloads dispose Overrides to clean Sub Dispose(ByVal up the component disposing list. As Boolean) Protected If disposing Overloads Then Overrides Sub Dispose(ByVal disposing As Boolean) If If disposing Not (components Then Is Nothing) Then If Not (components Is Nothing) Then Ifcomponents.Dispose() End IfEnd If MyBase.Dispose(disposing) End If End Sub MyBase.Dispose(disposing) 'Required End Sub by the Windows Form Designer Private 'Required components by the Windows As System.ComponentModel.IContainer Form Designer Private components As System.ComponentModel.IContainer Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend Friend WithEvents Button1 TextBox1 As As System.Windows.Forms.Button System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Friend WithEvents Button1 As System.Windows.Forms.Button Private Sub InitializeComponent() <System.Diagnostics.DebuggerStepThrough()> Me.TextBox1 = New System.Windows.Forms.TextBox Private Sub InitializeComponent() Me.Button1 Me.TextBox1 = New = New System.Windows.Forms.Button System.Windows.Forms.TextBox Me.SuspendLayout() Me.Button1 = New System.Windows.Forms.Button ' Me.SuspendLayout() 'TextBox1 ' ' 'TextBox1 Me.TextBox1.Location ' = New System.Drawing.Point(24, 16) Me.TextBox1.Multiline Me.TextBox1.Location = True New System.Drawing.Point(24, 16) Me.TextBox1.Name Me.TextBox1.Multiline = "TextBox1" = True Me.TextBox1.Size Me.TextBox1.Name = = New "TextBox1" System.Drawing.Size(200, 168) Me.TextBox1.TabIndex Me.TextBox1.Size = New = 0 System.Drawing.Size(200, 168) Me.TextBox1.Text Me.TextBox1.TabIndex = "" = 0 ' Me.TextBox1.Text = "" 'Button1 ' ' 'Button1 Me.Button1.Location ' = New System.Drawing.Point(200, 192) Me.Button1.Name Me.Button1.Location = "Button1" = New System.Drawing.Point(200, 192) Me.Button1.Size Me.Button1.Name = = New "Button1" System.Drawing.Size(80, 56) Me.Button1.TabIndex Me.Button1.Size = New = 1 System.Drawing.Size(80, 56) Me.Button1.Text Me.Button1.TabIndex = "E&xit" = 1 ' Me.Button1.Text = "E&xit" 'Form1 ' ' 'Form1 Me.AutoScaleBaseSize ' = New System.Drawing.Size(5, 13) Me.ClientSize Me.AutoScaleBaseSize = New System.Drawing.Size(292, = New System.Drawing.Size(5, 266) 13) Me.Controls.Add(Me.Button1) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button1) Me.Name Me.Controls.Add(Me.TextBox1) = "Form1" Me.Text Me.Name = = "Form1" Me.ResumeLayout(False) Me.Text = "Form1" Me.ResumeLayout(False) End Sub End Sub #End Region #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 Integer Dim prime As Boolean Dim i As Integer For i = 1 To 100 prime = True For j = 2 To (i / 2) If ((i Mod j) = 0) Then prime = False End If Next j If (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 Example VB.NET Code W.Buchanan (35)

using System; using using System.Drawing; System; using using System.Collections; System.Drawing; using using System.ComponentModel; System.Collections; using using System.Windows.Forms; System.ComponentModel; using using System.Data; System.Windows.Forms; using System.Data; namespace WindowsApplication1 namespace WindowsApplication1 public class Form1 : System.Windows.Forms.Form public class Form1 : System.Windows.Forms.Form private System.Windows.Forms.TextBox textbox1; private System.Windows.Forms.Button System.Windows.Forms.TextBox button1; textbox1; /// private <summary> System.Windows.Forms.Button button1; /// /// Required <summary> designer variable. /// /// </summary> Required designer variable. private /// </summary> System.ComponentModel.Container components = null; private System.ComponentModel.Container components = null; public Form1() public Form1() InitializeComponent(); InitializeComponent(); protected override void Dispose( bool disposing ) protected override void Dispose( bool disposing ) if( disposing ) if( disposing ) if (components!= null) if (components!= null) components.dispose(); components.dispose(); base.dispose( disposing ); base.dispose( disposing ); #region Windows Form Designer generated code private #region void Windows InitializeComponent() Form Designer generated code private void InitializeComponent() this.textbox1 = new System.Windows.Forms.TextBox(); this.button1 this.textbox1 = new = new System.Windows.Forms.Button(); System.Windows.Forms.TextBox(); this.suspendlayout(); this.button1 = new System.Windows.Forms.Button(); this.suspendlayout(); // // // textbox1 // // textbox1 this.textbox1.location // = new System.Drawing.Point(24, 16); this.textbox1.multiline this.textbox1.location = true; new System.Drawing.Point(24, 16); this.textbox1.name this.textbox1.multiline = "textbox1"; = true; this.textbox1.name = "textbox1"; this.textbox1.size = new System.Drawing.Size(184, 152); this.textbox1.size = new System.Drawing.Size(184, 152); this.textbox1.tabindex = 0; this.textbox1.text this.textbox1.tabindex = ""; = 0; // this.textbox1.text = ""; // // button1 // // button1 this.button1.location // = new System.Drawing.Point(200, 208); this.button1.name this.button1.location = "button1"; = new System.Drawing.Point(200, 208); this.button1.size this.button1.name = = new "button1"; System.Drawing.Size(72, 48); this.button1.tabindex this.button1.size = new = 1; System.Drawing.Size(72, 48); this.button1.text this.button1.tabindex = "E&xit"; = 1; this.button1.click this.button1.text += = "E&xit"; new System.EventHandler(this.button1_Click); // this.button1.click += new System.EventHandler(this.button1_Click); // Example C# code // 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(); W.Buchanan (36)

Benefits Why C#? Why? W.Buchanan (37)

C Language Language #include #include <stdio.h> <stdio.h> #include #include <math.h> <math.h> int int main(void) main(void) float float a,b,c,real1,real2,imag; a,b,c,real1,real2,imag; puts("program puts("program to to determine determine roots roots of of a a quadratic quadratic equation"); equation"); printf("enter printf("enter a,b a,b and and c c >>>"); >>>"); scanf("%f scanf("%f %f %f %f",&a,&b,&c); %f",&a,&b,&c); printf("equation printf("equation is is %.2fx*x %.2fx*x + + %.2fx %.2fx + + %.2f\n",a,b,c); %.2f\n",a,b,c); if if ((b*b)==(4*a*c)) ((b*b)==(4*a*c)) real1=-b/(2*a); real1=-b/(2*a); printf("root printf("root is is %.2f\n",real1); %.2f\n",real1); else else if if ((b*b)>(4*a*c)) ((b*b)>(4*a*c)) real1=(-b+sqrt( real1=(-b+sqrt( (b*b)-4*a*c (b*b)-4*a*c )) )) /(2*a); /(2*a); -Flexible. real2=(-b-sqrt( real2=(-b-sqrt( (b*b)-4*a*c (b*b)-4*a*c )) )) /(2*a); /(2*a); printf("roots printf("roots are are %.2f, %.2f, %.2f\n",real1,real2); %.2f\n",real1,real2); else else real1=-b/(2*a); real1=-b/(2*a); imag=sqrt(4*a*c-b*b)/(2*a); imag=sqrt(4*a*c-b*b)/(2*a); printf("roots printf("roots are are %.2f %.2f +/- +/- j%.2f\n",real1,imag); j%.2f\n",real1,imag); return(0); return(0); C Programming to Advantages: Advantages: -Minimal -Minimal language. language. -Standardized. -Standardized. -Flexible. Disadvantages: Disadvantages: -Weak -Weak checking checking for for errors. errors. -Focused -Focused on on procedures procedures rather rather than than data. data. -Lack -Lack of of support support for for graphics graphics (such (such as as Windows). Windows). W.Buchanan (38)

C Language C++ C++ Language Language #include #include <iostream.h> <iostream.h> class class circuit circuit private: private: float float rtemp; rtemp; public: public: float float parallel(float parallel(float r1, r1, float float r2) r2) return((r1*r2)/(r1+r2)); return((r1*r2)/(r1+r2)); float float series(float series(float r1, r1, float float r2) r2) return(r1+r2); return(r1+r2); ; ; int int main(void) main(void) circuit circuit c1; c1; float float res; res; res=c1.series(2000,1000); res=c1.series(2000,1000); cout cout << << "Series "Series resistance resistance is is " " << << res res << << "ohms\n"; "ohms\n"; res=c1.parallel(1000,1000); res=c1.parallel(1000,1000); cout cout << << "Parallel "Parallel resistance resistance is is " " << << res res << << "ohms\n"; "ohms\n"; return(0); return(0); C Programming to Object-orientation added Advantages: Advantages: -Standardized. -Standardized. -Flexible. -Flexible. -Object-oriented. -Object-oriented. -Improved -Improved error error checking. checking. -Improved -Improved Windows Windows support support Disadvantages: Disadvantages: -Still -Still a hybrid hybrid language language (C (C and/or and/or C++). C++). -Still -Still too too generic. generic. -Lack -Lack of of integration integration with with other other languages. languages. W.Buchanan (39)

C Language using using System; System; C++ Language namespace namespace ConsoleApplication2 ConsoleApplication2 public public class class Circuit Circuit public public double double Parallel(double Parallel(double r1, r1, double double r2) r2) return((r1*r2)/(r1+r2)); return((r1*r2)/(r1+r2)); public public double double Series(double Series(double r1, r1, double double r2) r2) Advantages: Advantages: return(r1+r2); return(r1+r2); -Robust. -Robust. class class Class1 Class1 -Cross-platform. -Cross-platform. static static void void Main(string[] Main(string[] args) args) double double v1=100,v2=100; v1=100,v2=100; double double res; res; Circuit Circuit cir cir = = new new Circuit(); Circuit(); res=cir.parallel(v1,v2); res=cir.parallel(v1,v2); Disadvantages: System.Console.WriteLine("Parallel System.Console.WriteLine("Parallel resistance resistance is Disadvantages: is 0 0 ohms",res); ohms",res); res=cir.series(100,100); res=cir.series(100,100); System.Console.WriteLine("Series System.Console.WriteLine("Series resistance resistance is is 0 environment. 0 environment. ohms",res); ohms",res); System.Console.ReadLine(); System.Console.ReadLine(); C Programming to C# C# Language Language Windows/ WWW/ Java ideas -Fully -Fully object-oriented. object-oriented. -Integrated -Integrated with with Windows. Windows. -Support -Support for for mobility. mobility. -Strong -Strong integration integration with with -Massive -Massive programming programming W.Buchanan (40)

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. Why C#? W.Buchanan (41)

Elements of a C# Program What goes where? Why? W.Buchanan (42)

using 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); be be static. static. 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(); C# Program Outline using. using. Imports Imports types types defined defined in in other other namespaces. namespaces. namespace. namespace. Defines Defines a a unique unique name name for for the the objects. objects. In In this this case case the the objects objects would would have have the the name name of: of: ConsoleApplications2.Complex() ConsoleApplications2.Complex() ConsoleApplicaitons2.Class1() ConsoleApplicaitons2.Class1() Main(). Main(). This This is is the the entry entry point point into into the the program, program, and and defines defines the the start start and and end end of of the the program. program. It It must must be be declared declared inside inside a a class, class, and and must must W.Buchanan (43)

using 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(); C# Program Outline namespace. namespace. Defines Defines a a unique unique name name for for the the objects. objects. In In this this case case the the objects objects would would have have the the name name of: of: ConsoleApplications2.Complex() ConsoleApplications2.Complex() ConsoleApplicaitons2.Class1() ConsoleApplicaitons2.Class1() W.Buchanan (44)

using. using. Imports Imports types types defined defined in in System.Console.Write("Enter real value >> other "); other namespaces. namespaces. System.Console. W.Buchanan (45)

Math.Sqrt(real*real+imag*imag) using. using. Imports Imports types types defined defined in in other other namespaces. namespaces. System.Math. W.Buchanan (46)

System: Array, Boolean, Byte, Char, Convert, DateTime, Double, Enum, Int16, Int32, Int 64, Math, Random, String, Void System.Collections: ArrayList, BitArray, Hashtable, Queue, Stack. System.IO: BinaryReader, BinaryWriter, File, Stream, StreamWriter, StreamReader uses System; uses System.Collections; uses System.IO Typical namespaces W.Buchanan (47)

.NET Components What are components? Why? W.Buchanan (48)

Application uses components to gain access to services MS MS Word Word component MS MS Outlook component MS MS IE IE component New.NET Platform W.Buchanan (49)

Conclusions?.NET Languages W.Buchanan (50)

3: Arrays and Collections Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1)

Course Outline Day 1: Morning Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Day 1: Afternoon Data Types, Variables, Converting Data Types, if, for, while, File Handling Day 2: Morning Arrays, System.Collections, ArrayLists, Hashtables. Day 2: Afternoon Reference-Type Variables, Common Reference Types, Object Hierarchy, Namespaces, Debugging. Day 3: Morning Methods, Exceptions, Namespaces, Modules/ Assemblies, Non-visual Components, Regular Expressions, Intellisense, Help, Delegates, Events. Day 3: Afternoon Cerebus, Limit-check components, Power meter class. Course Outline (Day 1 to 3) W.Buchanan (2)

Course Outline Day 4: Morning Classes, Encapsulation, Object-Orientation, Classes, Sealed Classes, Interfaces, Abstract Classes. Day 4: Afternoon Using Constructors, Initializing Memory, Objects and Memory, Resource Management. Day 5: Morning Cerebus: 1mW Test. Day 5: Afternoon Operators, Operator Overloading, Attributes, Custom Attributes, Retrieving Attribute Values. Course Outline (Day 4 and 5) W.Buchanan (3)

Module 3 Arrays. Reading from CSV files. System.Collections. ArrayLists. HashTables. Introduction W.Buchanan (4)

System.Array object: Methods include: BinarySearch() Clear() Clone() Copy() CopyTo() CreateInstance() GetLength() IndexOf() Initialize() LastIndexOf() Reverse() SetValue() Sort() IsFixedSize IsReadOnly Length Performs a binary on a one-dimensional array Sets a range of elements to zero, False or NULL. Make a shallow copy of the array. Copies a range of values in an array. Copies one array to another. Create a multidimensional array. Return the number of elements in the array. Search for an object, and return the first index value of its place. Set all the elements in the array to their default value. Returns the last object in the array. Reverses the array. Sets a specific array element to a value. Performs a sort on the array. Identifies if the array is a fixed size (get only) Identifies if the array is read-only (get only) Identifies the length of the array (get only) W.Buchanan (5)

Variables ArrayName k k i i j j Reference to the start of the array space. Allocated on the heap. Element Element 0 Element Element 1 Element Element 2 Element Element 3 Element Element 4 Element Element n-2 n-2 Element Element n-1 n-1 Variables and Arrays W.Buchanan (6)

W.Buchanan (7)

C# contains the methods of the System.Array object. It also inherits the syntax of C for representing an array index, which uses square brackets to identify the element, such as: myarray[15]; for the element number 15. Note that C# starts its indexing at 0, thus myarray[15] is the 16th element of the array. To declare an array: type[] arrayname; For example to declare an array of doubles: double[] inputvalues; This declares the type of the array. To then to initialize it the following is used: inputvalues = new double[5]; which creates a new array with 5 elements (0 to 4). ArrayName Element 0 Element 1 Element 2 Element 3 Element 4 Element n-2 Element n-1 W.Buchanan (8)

namespace ConsoleApplication2 class ArrayExample01 static void getvalues(double[] v) int i; for (i=0;i<v.length;i++) System.Console.Write("Value >> "); v[i]=convert.todouble(system.console.readline()); static double average(double[] v) double total=0; int i; for (i=0;i<v.length;i++) total+=v[i]; return(total/v.length); static void Main(string[] args) int i; double[] inputvalues; double av; inputvalues = new double[5]; getvalues(inputvalues); av=average(inputvalues); System.Console.WriteLine("Average is 0",av); System.Console.ReadLine(); W.Buchanan (9)

Note that the declaration of the array type does not actually create the array, and the line: double[] inputvalues; double av av=inputvalues[0]; will cause a build error of: Use of unassigned local variable 'inputvalues' As the array can not been created yet, and just contains a null value. Using an array W.Buchanan (10)

The arrays when they are initialized are set to a default value, such as zero for numeric data types, and null for strings. To initialise it with actual values, the required values are contained within curly brackets, such as: double[] vals = 1.2,1.4,1.6,1.8,2.0; string[] menuitems = "File", "Edit", "View", "Insert", "Tool", "Table"; This performs both the declaration of the array and its initialization. Program 3.2 shows an example of the declaration of an array of strings. W.Buchanan (11)

using System; namespace ConsoleApplication2 class ArrayExample01 static void Main(string[] args) int i; string[] ColourBands="BLACK","BROWN","RED","ORANGE","YELLOW", "GREEN"; for (i=0;i<colourbands.length;i++) System.Console.WriteLine("0 is 1",i,ColourBands[i]); System.Console.ReadLine(); W.Buchanan (12)

using System; namespace ConsoleApplication2 class ArrayExample01 static double findsmallest(double[] v) double smallest; smallest=v[0]; for (int i=1; i<v.length; i++) if (v[i]<smallest) smallest = v[i]; return(smallest); static void Main(string[] args) int i; double[] vals = 1.2,4.5,13.3,10.1,-4.3,52.5,6.2; double smallest; smallest= findsmallest(vals); System.Console.WriteLine("Smallest value is 0",smallest); System.Console.ReadLine(); W.Buchanan (13)

foreach (type identifier in expression) statement Thus: for (i=0;i<colourbands.length;i++) System.Console.WriteLine("0 is 1",i,ColourBands[i]); is replaced by (Program3_3_ArrayInitializationNumericForEach): foreach (string band in ColourBands) System.Console.WriteLine("0",band); For the example in Program 3.2 we can replace: for (int i=1; i<v.length; i++) if (v[i]<smallest) smallest = v[i]; with (Program3_4_ArrayInitializationStringsForEach): foreach (double val in v) if (val<smallest) smallest = val; foreach W.Buchanan (14)

using System; namespace ConsoleApplication2 class ArrayExample01 static double findsmallest(double[] v) double smallest; smallest=v[0]; foreach (double val in v) if (val<smallest) smallest = val; return(smallest); static void Main(string[] args) int i; double[] vals = 1.2,4.5,13.3,10.1,-4.3,52.5,6.2; double smallest; smallest= findsmallest(vals); System.Console.WriteLine("Smallest value is 0",smallest); System.Console.ReadLine(); W.Buchanan (15)

1,5,6,7,4,5,6,7,10,5,4,3,2,1 For this we can read the file one line at a time, and then split the string using the Split() method. This can be contained with the foreach statement, to parse each part of the split text. The code which fills the array v is: do text=reader.readline(); if (text==null) break; foreach (string substring in text.split(',')) v[i]=convert.todouble(substring); i++; while (text!= null); Reading a CSV file W.Buchanan (16)

class ArrayExample02 const int ARRAYLIMIT=100; static void filldata(double[] v) int i=0; FileInfo thesourcefile = new FileInfo("..\\..\\test.csv"); StreamReader reader = thesourcefile.opentext(); string text; do text=reader.readline(); if (text==null) break; foreach (string substring in text.split(',')) v[i]=convert.todouble(substring); i++; while (text!= null); reader.close(); W.Buchanan (17)

Often the CSV file is organised into rows with comma separated variables in each row. This is similar to a spreadsheet where the row is represented by a line, and the columns are delimited by commas. For example: Fred,20 Bert,10 Colin,15 Berty,26 Freddy,22 We can then modify the reading method to parse the input line from the CSV file: do text=reader.readline(); if (text==null) break; string[] str =text.split(','); name[i]=str[0]; age[i]=convert.toint32(str[1]); i++; while (text!= null); CSV W.Buchanan (18)

Microsoft.Win32 System System.Collections System.Configuration System.Configuration.Assemblies System.Diagnostics System.Diagnostics.SymbolStore System.Globalization System.IO System.IO.IsolatedStorage System.Reflection System.Reflection.Emit System.Resources System.Runtime System.Runtime.CompilerServices System.Runtime.InteropServices System.Runtime.InteropServices.Expando System.Runtime.Remoting System.Runtime.Remoting.Activation System.Runtime.Remoting.Channels System.Runtime.Remoting.Contexts System.Runtime.Remoting.Lifetime System.Runtime.Remoting.Messaging System.Runtime.Remoting.Metadata System.Runtime.Remoting.Proxies System.Runtime.Remoting.Services System.Runtime.Serialization System.Runtime.Serialization.Formatters System.Security System.Security.Cryptography Typical Namespaces W.Buchanan (19)

System.Collections ArrayList BitArray CaseInsensitiveComparer CaseInsensitiveHashCodeProvider CollectionBase Comparer DictionaryBase DictionaryEntry Hashtable Queue ReadOnlyCollectionBase SortedList Stack W.Buchanan (20)

Conclusions?.NET Languages W.Buchanan (21)

Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1)

Course Outline Day 1: Morning Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Day 1: Afternoon Data Types, Variables, Converting Data Types, if, for, while, File Handling Day 2: Morning Arrays, System.Collections, ArrayLists, Hashtables. Day 2: Afternoon Reference-Type Variables, Common Reference Types, Object Hierarchy, Namespaces, Debugging. Day 3: Morning Methods, Exceptions, Namespaces, Modules/ Assemblies, Non-visual Components, Regular Expressions, Intellisense, Help, Delegates, Events. Day 3: Afternoon Cerebus, Limit-check components, Power meter class. Course Outline (Day 1 to 3) W.Buchanan (2)

Course Outline Day 4: Morning Classes, Encapsulation, Object-Orientation, Classes, Sealed Classes, Interfaces, Abstract Classes. Day 4: Afternoon Using Constructors, Initializing Memory, Objects and Memory, Resource Management. Day 5: Morning Cerebus: 1mW Test. Day 5: Afternoon Operators, Operator Overloading, Attributes, Custom Attributes, Retrieving Attribute Values. Course Outline (Day 4 and 5) W.Buchanan (3)

Module 7 Classes and objects. Revision! Using encapsulation. Defining Object-Oriented Systems. Inheritance. Sealed classes. Overriding classes. Introduction W.Buchanan (4)

An Introduction to Object- Orientation Bill Buchanan Introduction W.Buchanan (5)

Some Cups W.Buchanan (6)

Parameter Cup 1 Cup 2 Cup3 Shape (Standard/Square/Mug) Standard Square Mug Colour (Red/Blue/Green) Blue Red Green Size (Small/Medium/Large) Small Large Small Transparency (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 are created from classes. A Quick Introduction to Object-Orientation W.Buchanan (7)

using System; namespace ConsoleApplication2 Class definitions public class Cup public string Shape; public string Colour; public string Size; public int Transparency; public string Handle; Available variables (properties) Method 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(); Create new object Set properties Apply method Example C# Program using Object-Orientation W.Buchanan (8)

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 definitions 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(); Another example W.Buchanan (9)

using 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(); z = x + jy z z = x 2 = tan + y 1 2 y x Another example W.Buchanan (10)

Object Properties Bill Buchanan Introduction W.Buchanan (11)

Make. This could be Ford, Vauxhall, Nissan or Toyota. Type. This could be Vectra, Astra, or Mondeo. Colour. This could be colours such as Red, Green or Blue. Country of Manufacture. This could be countries such as UK, Germany or France. Car properties W.Buchanan (12)

using using System; System; namespace namespace sample01 sample01 public public class class Car Car private private string string colour; colour; private private string string type; type; private private string string make; make; private private string string country; country; private private double double cost; cost; public public string string Colour Colour get get return return colour; colour; set set colour=value; colour=value; public public string string Type Type get get return return type; type; set set type=value; type=value; public public string string Country Country get get return return country; country; set set country=value; country=value; public public string string Make Make get get return return make; make; set set make=value; make=value; public public double double Cost Cost get return cost; get return cost; set cost=value; set cost=value; Relationship Tree class Class1 static void Main(string[] args) Car car1 = new Car(); car1.colour="red"; car1.make="ford"; car1.type="mondeo"; car1.colour="uk"; car1.cost=15000; Console.WriteLine( "Car is a " + car1.make + " " + car1.type); Console.ReadLine(); W.Buchanan (13)

public double Cost get return cost; Read-only Read/write public double Cost set val=value; public double Cost set val=value; get return cost; Write-only Read-only, write-only and read/write properties W.Buchanan (14)

Object-Orientation Bill Buchanan Introduction W.Buchanan (15)

Let s Look At Real Objects W.Buchanan (16)

Plants Plants Animals Minerals Skin with fur/hair. Red blooded. Warm blooded. Backbone Vertebrates Mammals Invertebrates Birds Birds Classification W.Buchanan (17)

Collection Vertebrates Mammals Increasing generalisation Cats Cats Dogs Dogs Horses Horses Lion Lion Tiger Tiger Relationship Tree Domestic Domestic Shared behaviours and characteristics Increasing specialisation W.Buchanan (18)

containers System Increasing generalisation Windows IO IO Drawing Component Component Model Model Design Design Forms Forms Label Label Combo Combo Box Box Button Button Form Form Class Increasing specialisation Relationship Tree W.Buchanan (19)

using using System.Collections; System.Collections; using using System.Windows.Forms; System.Windows.Forms; Derived using using System.Data; System.Data; namespace namespace WindowsApplication3 class WindowsApplication3 public public class class Form1 Form1 : : System.Windows.Forms.Form Base System.Windows.Forms.Form containers class private private System.Windows.Forms.Button System.Windows.Forms.Button button1; button1; private private System.Windows.Forms.TextBox System.Windows.Forms.TextBox textbox1; textbox1; public public Form1() Form1() System InitializeComponent(); InitializeComponent(); private private void void InitializeComponent() InitializeComponent() this.button1 this.button1 = new new System.Windows.Forms.Button(); System.Windows.Forms.Button(); this.textbox1 this.textbox1 = = new new System.Windows.Forms.TextBox(); System.Windows.Forms.TextBox(); this.button1.location this.button1.location = = new new System.Drawing.Point(152, System.Drawing.Point(152, 192); 192); this.button1.name this.button1.name = = "button1"; "button1"; this.button1.tabindex this.button1.tabindex = = 0; 0; this.button1.text this.button1.text = = "button1"; "button1"; this.textbox1.location this.textbox1.location = = new new System.Drawing.Point(80, System.Drawing.Point(80, 64); 64); this.textbox1.name this.textbox1.name = = "textbox1"; "textbox1"; this.textbox1.text this.textbox1.text = = "textbox1"; "textbox1"; Component this.controls.add(this.textbox1); Component this.controls.add(this.textbox1); Forms Model this.controls.add(this.button1); Forms Model this.controls.add(this.button1); this.name this.name = = "Form1"; "Form1"; this.text this.text = = "Form1"; "Form1"; Design this.load Design this.load += += new new System.EventHandler(this.Form1_Load); System.EventHandler(this.Form1_Load); this.resumelayout(false); this.resumelayout(false); static Combo static void void Main() Main() Combo Label Box Application.Run(new Label Form1()); Box Application.Run(new Form1()); Relationship private void Form1_Load(object private voidtree sender, System.EventArgs e) Form1_Load(object sender, System.EventArgs e) W.Buchanan (20) this means Windows this object (which is Form1)

Inheritance Bill Buchanan Introduction W.Buchanan (21)

Inheritance Derives characteristics and behaviours from those above us. Inheritance W.Buchanan (22)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 class class People People private private string string name; name; public containers public string string Name Name get get return return name; name; set set name=value; name=value; System public public void void ToLowerCase() ToLowerCase() name=name.tolower(); name=name.tolower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Windows Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); class class Test Test Component static Component static void void Main() Main() Forms Model Forms Model Profile Profile p1 p1 = = new new Profile(); Profile(); p1.name="fred"; p1.name="fred"; Design p1.tolowercase(); Design p1.tolowercase(); p1.display(); p1.display(); System.Console.ReadLine(); System.Console.ReadLine(); Combo Combo Label Box Label Box Inheritance Inherent from People Method derived from People People People Name: fred Profile Profile W.Buchanan (23)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 class class People People private private string string name; name; public containers public string string Name Name get get return return name; name; set set name=value; name=value; System public public void void ToLowerCase() ToLowerCase() name=name.tolower(); name=name.tolower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Windows Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); class class Test Test Component static Component static void void Main() Main() Forms Model Forms Model Profile Profile p1 p1 = = new new Profile(); Profile(); Profile Profile p2 p2 = = new new Profile(); Profile(); Design p1.name="fred"; Design p1.name="fred"; p2.name="bert"; p2.name="bert"; p1.tolowercase(); p1.tolowercase(); p1.display(); Combo p1.display(); Combo p2.display(); p2.display(); Label Box System.Console.ReadLine(); Label Box System.Console.ReadLine(); Inheritance Inherent from People People People Name: fred Name: Bert Profile Profile W.Buchanan (24)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 sealed sealed class class People People private private string string name; name; public containers public string string Name Name get get return return name; name; set set name=value; name=value; System public public void void ToLowerCase() ToLowerCase() name=name.tolower(); name=name.tolower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Windows Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); class class Test Test Component static Component static void void Main() Main() Forms Model Forms Model Profile Profile p1 p1 = = new new Profile(); Profile(); p1.name="fred"; p1.name="fred"; Design p1.tolowercase(); Design p1.tolowercase(); p1.display(); p1.display(); System.Console.ReadLine(); System.Console.ReadLine(); Combo Combo Label Box Label Box Sealed Classes Inherent from People People People Profile Profile 'ConsoleApplication1.Profile' : cannot inherit from sealed class 'ConsoleApplication1.People' W.Buchanan (25)

Overriding Classes Bill Buchanan Introduction W.Buchanan (26)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 class class Test Test class class People People static static void void Main() Main() private private string string name; name; Profile Profile p1 p1 = = new new Profile(); Profile(); public public string string Name Name p1.name="fred"; p1.name="fred"; get get return return name; name; set set name=value; p1.tolowercase(); name=value; p1.tolowercase(); p1.display(); p1.display(); public public virtual virtual void void ToLowerCase() ToLowerCase() System.Console.ReadLine(); System.Console.ReadLine(); name=name.tolower(); name=name.tolower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Method has been overwritten Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); Name: Fred public public override override void void ToLowerCase() ToLowerCase() Console.WriteLine("Method Console.WriteLine("Method has has been been overwritten"); overwritten"); W.Buchanan (27) Overriding classes

Object Equals(). Determines if two objects are the same. Finalize(). Cleans up the object (the destructor). GetHashCode(). Allows an object to define its hash code. GetType(). Determine the type of an object. MemberwiseClone(). Create a copy of the object. ReferenceEquals(). Determines whether two objects are of the same instance. ToString(). Convert an object to a string. Methods for the default object W.Buchanan (28)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 class class Test Test class class People People static static void void Main() Main() private private string string name; name; public public string string Name Profile Name Profile p1 p1 = = new new Profile(); Profile(); p1.name="fred"; p1.name="fred"; get get return return name; string name; string str=p1.tostring(); str=p1.tostring(); set set name=value; Console.WriteLine(str); name=value; Console.WriteLine(str); System.Console.ReadLine(); System.Console.ReadLine(); public public virtual virtual void void ToLowerCase() ToLowerCase() name=name.tolower(); name=name.tolower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); public public override override string string ToString() ToString() return("cannot return("cannot implement implement this this method"); method"); W.Buchanan (29)

Abstract Classes Bill Buchanan Introduction W.Buchanan (30)

Here Here is is the the new new object, object, but but you you can t can t use use it it unless unless you you implement your your own own OpenTheBox() method! Okay. Okay. It s It s worth worth it. it. I ll I ll do do that. that. Abstract Classes W.Buchanan (31)

An example W.Buchanan (32)

using using System; System; namespace namespace ConsoleApplication1 ConsoleApplication1 abstract abstract class class People People private private string string name; name; public public string string Name Name get get return return name; name; set set name=value; name=value; public public void void ToLowerCase() ToLowerCase() name=name.tolower(); name=name.tolower(); abstract abstract public public void void DisplayLower(); DisplayLower(); class class Profile Profile : : People People // // Inherit Inherit from from People People public public void void Display() Display() Console.WriteLine("Name: Console.WriteLine("Name: "+Name); "+Name); class class Test Test static static void void Main() Main() Profile Profile p1 p1 = = new new Profile(); Profile(); p1.name="fred"; p1.name="fred"; p1.tolowercase(); p1.tolowercase(); p1.display(); p1.display(); p1.displaylower(); p1.displaylower(); System.Console.ReadLine(); System.Console.ReadLine(); 'ConsoleApplication1.Profile' does not implement inherited abstract member 'ConsoleApplication1.People.DisplayLower()' Abstract Classes W.Buchanan (33)

using System; namespace ConsoleApplication1 abstract class People private string name; public string Name get return name; set name=value; public void ToLowerCase() name=name.tolower(); abstract public void DisplayLower(); class Profile : People // Inherit from People public void Display() Console.WriteLine("Name: "+Name); public override void DisplayLower() Console.WriteLine("Name: "+Name.ToUpper()); Abstract Classes class class Test Test static static void void Main() Main() Profile Profile p1 p1 = = new new Profile(); Profile(); p1.name="fred"; p1.name="fred"; p1.tolowercase(); p1.tolowercase(); p1.display(); p1.display(); p1.displaylower(); p1.displaylower(); System.Console.ReadLine(); System.Console.ReadLine(); Name: fred Name: FRED W.Buchanan (34)

Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1)

Course Outline Day 1: Morning Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Day 1: Afternoon Data Types, Variables, Converting Data Types, if, for, while, File Handling Day 2: Morning Arrays, System.Collections, ArrayLists, Hashtables. Day 2: Afternoon Reference-Type Variables, Common Reference Types, Object Hierarchy, Namespaces, Debugging. Day 3: Morning Methods, Exceptions, Namespaces, Modules/ Assemblies, Non-visual Components, Regular Expressions, Intellisense, Help, Delegates, Events. Day 3: Afternoon Cerebus, Limit-check components, Power meter class. Course Outline (Day 1 to 3) W.Buchanan (2)

Course Outline Day 4: Morning Classes, Encapsulation, Object-Orientation, Classes, Sealed Classes, Interfaces, Abstract Classes. Day 4: Afternoon Using Constructors, Initializing Memory, Objects and Memory, Resource Management. Day 5: Morning Cerebus: 1mW Test. Day 5: Afternoon Operators, Operator Overloading, Attributes, Custom Attributes, Retrieving Attribute Values. Course Outline (Day 4 and 5) W.Buchanan (3)

Module 8 Interfaces. Constructors and destructors. Static and instance members. Memory. Introduction W.Buchanan (4)

Interfaces Bill Buchanan Introduction W.Buchanan (5)

Here Here is is the the new new object, object, but but you you must must implement it it in in every every way way that that I I have have defined! Pweh! Pweh! You re You re rather rather strict. strict. Interfaces W.Buchanan (6)

r 1 r 2 R T = R 1 + R 2 r 1 Circuit r 2 R 1 R T = R1 + R 2 R 2 Circuit Object W.Buchanan (7)

r 1 r 2 R T = R 1 + R 2 r 1 r 2 interface NewCircuit double r1 r1 set; set; get; get; double r2 r2 set; set; get; get; double calcparallel(); double calcseries(); R 1 R T = R1 + R 2 R 2 Interface Definition W.Buchanan (8)

r 1 r 2 public class Circuit: NewCircuit private double res1, res2; public double r1 r 1 set res1=value; get return res1; public double r2 r 2 set res2=value; get return res2; public double calcparallel() return((r1*r2)/(r1+r2)); public double calcseries() return(r1+r2); Derived Class Definition R T = R 1 + R 2 R 1 R T = R1 + R 2 R interface NewCircuit double r1 r1 set; set; get; get; double r2 r2 set; set; get; get; double calcparallel(); double calcseries(); 2 W.Buchanan (9)

r 1 r 2 public class Circuit: NewCircuit private double res1, res2; public double r1 set res1=value; get return res1; public double r2 set res2=value; get return res2; public double calcparallel() return((r1*r2)/(r1+r2)); public double calcseries() return(r1+r2); Derived Class Definition r 1 r 2 R T = R 1 + R 2 R public class Class1 1 R T = static void Main() R1 + R 2 R Circuit cir = new Circuit(); cir.r1=1000; cir.r2=1000; double res = cir.calcparallel(); System.Console.WriteLine( "Parallel Resistance is " + res); System.Console.ReadLine(); 2 W.Buchanan (10)

IOCollection. Defines size, enumerators and synchronization methods for all collections. The public properties are: Count, IsSynchronized and SyncRoot, and a method of CopyTo(). IComparer. Compares two objects. The associated method is Compare(). IEnumerator. Supports iteration over a collection. The properties are Current, and the methods are MoveNext() and Reset(). IList. Represents a collection of objects that are accessed by an index. The properties are IsFixedSize, IsReadOnly, Item, and the methods are: Add(), Clear(), Contains(), IndexOf(), Insert(), Remove() and RemoveAt(). W.Buchanan (11)

W.Buchanan (12)

The IOCollection defines: The classes which implement IOCollection include: Array. ArrayList. Hastable. Thus an array will have the following properties: Count. IsSynchronized. SyncRoot W.Buchanan (13)

W.Buchanan (14)

Constructors Bill Buchanan Introduction W.Buchanan (15)

A constructor is a method that is called whenever the object is first created. A destructor is a method that is called whenever the object is destroyed. Constructors and destructors W.Buchanan (16)

class Profile string code, name, telephone; // Constructor public Profile(string c) code=c; public string Name set name=value; get return name; public string Telephone set telephone=value; get return telephone; public void Display() Console.WriteLine("Code: " + code + " Name: " + name + " Telephone: " + telephone); Console.ReadLine(); W.Buchanan (17)

class Profile string code, name, telephone; // Constructor public Profile(string c) code=c; public string Name set name=value; get return name; public string Telephone set telephone=value; pf1.telephone="123456"; pf1.display(); get return telephone; public void Display() class Class1 static void Main(string[] args) Profile pf1=new Profile("00000"); pf1.name="fred Smith"; Console.WriteLine("Code: " + code + " Name: " + name + " Telephone: " + telephone); Console.ReadLine(); W.Buchanan (18)

Static and Instance Members Bill Buchanan Introduction W.Buchanan (19)