Evaluation Copy. Visual Basic Essentials. Student Guide Revision 4.5. Object Innovations Course 4202

Size: px
Start display at page:

Download "Evaluation Copy. Visual Basic Essentials. Student Guide Revision 4.5. Object Innovations Course 4202"

Transcription

1 Visual Basic Essentials Student Guide Revision 4.5 Object Innovations Course 4202

2 Visual Basic Essentials Rev. 4.5 Student Guide Information in this document is subject to change without notice. Companies, names and data used in examples herein are fictitious unless otherwise noted. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Object Innovations. Product and company names mentioned herein are the trademarks or registered trademarks of their respective owners. Authors: Robert J. Oberg and Dana Wyatt is a trademark of Object Innovations. Copyright 2013 Object Innovations Enterprises, LLC All rights reserved.. Object Innovations Printed in the United States of America. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC ii

3 Table of Contents (Overview) Chapter 1.NET: What You Need to Know Chapter 2 Visual Basic for the Sophisticated Programmer Chapter 3 Object-Oriented Programming in Visual Basic Chapter 4 Chapter 5 Chapter 6 Visual Basic and the.net Framework Delegates and Events Introduction to Windows Forms Chapter 7 Newer Features in Visual Basic Appendix A Using Visual Studio 2012 Appendix B Learning Resources Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC iii

4 Directory Structure The course software installs to the root directory C:\OIC\VbEss. Example programs for each chapter are in named subdirectories of chapter directories Chap01, Chap02, and so on. Example programs for Appendix A are in the directory AppA. The Labs directory contains one subdirectory for each lab, named after the lab number. Starter code is frequently supplied, and answers are provided in the chapter directories. The CaseStudy directory contains a case study in multiple steps. The Demos directory is provided for performing in-class demonstrations led by the instructor. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC iv

5 Table of Contents (Detailed) Chapter 1.NET: What You Need to Know... 1 Getting Started... 3.NET: What Is Really Happening... 4.NET Programming in a Nutshell... 5.NET Program Example... 6 Viewing the Assembly... 7 Viewing Intermediate Language... 8 Understanding.NET... 9 Visual Studio Creating a Console Application Visual Studio Solutions Starter Code Using the Visual Studio Text Editor IntelliSense Build and Run the Project Pausing the Output Visual Basic and GUI Programs NET Documentation Summary Chapter 2 Visual Basic for the Sophisticated Programmer Visual Basic Hello, World Compiling, Running (Command Line) Program Structure Namespaces Project Imports Startup Object Variables Literals and Constants Operators Short-Circuit Operators More Operators Operator Precedence Control Structures Conditionals Looping Constructs Types in Visual Basic Object Simple Data Types Floating Point Data Types Implicit Conversions Explicit Conversions Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC v

6 Boolean Data Type Structure Enumeration Types Reference Types Class Types Object String Data Type Copying Strings StringBuilder Class Classes and Structures Arrays One Dimensional Arrays System.Array InputWrapper Class Input Wrapper Implementation Jagged Arrays Rectangular Arrays For Each for Arrays Boxing and Unboxing Output in Visual Basic Formatting Formatting Example Modules Subroutines and Functions Default Parameters Exceptions Exceptions Example Program System.Exception Implicit Line Continuation Lab Summary Chapter 3 Object-Oriented Programming in Visual Basic Visual Basic as an Object-Oriented Programming Language Classes vs. Objects Creating a Class Creating and Referencing Objects Bank Example Account Class Shared Members Auto-Implemented Properties Auto-Implemented Property Example Classes and Modules Self-Generating IDs Methods vs. Properties Defining Member Variables Adding Methods Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC vi

7 Adding Properties Overloading Methods Object Lifecycle Classes vs. Structures Inheritance Inheritance and Scope Invoking the Base Class Shadowing Base Class Methods Polymorphism Overriding Base Class Methods Heterogeneous Collections Abstract Classes Abstract Methods User Defined Exception Classes Operator Overloading Lab Summary Chapter 4 Visual Basic and the.net Framework Components and OO in Visual Basic Interfaces Interfaces in Visual Basic Implementing an Interface Using an Interface Multiple Interfaces Using Multiple Interfaces TypeOf... Is and Dynamic Interfaces Interfaces in Visual Basic and COM Resolving Ambiguity in Interfaces System.Object Collections ArrayList ArrayList Methods Example: StringList IEnumerable and IEnumerator Using Enumerators Collections of User-Defined Objects Account Class Collection Interfaces ICollection IList Default Properties Using the Item Property Copy Semantics in Visual Basic Arrays Shallow Copy and Deep Copy CopyDemo Example Program Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC vii

8 Reference Copy Memberwise Clone Using ICloneable Lab 4A Writing Generic Code Using a Class of Object Generic Types Generic Example Generic Client Code System.Collections.Generic Lab 4B Summary Chapter 5 Delegates and Events Overview of Delegates and Events Callbacks and Delegates Usage of Delegates Declaring a Delegate Defining a Method Creating a Delegate Object Calling a Delegate Random Number Generation A Random Array Combining Delegate Objects Account.vb DelegateAccount.vb Events Static and Dynamic Event Handling Dynamic Event Handling Chat Room Example Static Event Handling Lab Summary Chapter 6 Introduction to Windows Forms Creating a Windows Forms App IDE Generated Code in VB Partial Classes Windows Forms Event Handling Add Events for a Control Events Documentation Closing a Form ListBox Control ListBox Example My Command Line Arguments Lab Summary Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC viii

9 Chapter 7 Newer Features in Visual Basic Local Type Inference Local Type Inference Example Object Initializers Array Initializers Anonymous Types Partial Methods Partial Method Definition Partial Method Implementation Test Program Running the Example Extension Methods Extension Methods Example Collection Initializers Variance in Generic Interfaces Covariance Example Variance with IComparer(Of T) Interfaces with Variance Support Contravariance Example Language-Integrated Query (LINQ) LINQ Example Using IEnumerable(OfT> Iterators Yield Keyword Iterator Examples Asynchronous Programs in VB Task and Task(Of TResult) Aysnc Methods Async Example Synchronous Call Async Call Threading Summary Appendix A Using Visual Studio A Visual Studio Solution Toolbars Customizing a Toolbar Creating a Console Application Using the Visual Studio Text Editor Build and Run the Bytes Project Running the Bytes Project Executable File Location Managing Configurations Project Configurations Debugging Just-in-Time Debugging Demo Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC ix

10 Breakpoints Watch Variables Debug Toolbar Stepping with the Debugger Demo: Stepping with the Debugger Call Stack and Call Hierarchy Multiple-Project Solution Demo Adding a Reference Project Dependencies Startup Project Hidden Files Summary Appendix B Learning Resources Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC x

11 VbEss Chapter 1 Chapter 1.NET: What You Need to Know Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 1

12 VbEss Chapter 1.NET: What You Need to Know Objectives After completing this unit you will be able to: Describe the essentials of creating and running a program in the.net environment. Build and run a simple Visual Basic program in the.net environment. Use the ILDASM tool to view intermediate language. Use Visual Studio 2012 as an effective environment for creating Visual Basic programs. Use the.net Framework SDK documentation. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 2

13 VbEss Chapter 1 Getting Started From a programmer s perspective, a beautiful thing about.net is that you scarcely need to know anything about it to start writing programs for the.net environment. You write a program in a high-level language (such as Visual Basic), a compiler creates an executable.exe file (called an assembly), and you run that.exe file. Even very simple programs, if they are designed to do something interesting, such as perform output, will require that the program employ the services of library code. A large library, called the.net Framework Class Library, comes with.net, and you can use all of the services of this library in your programs. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 3

14 VbEss Chapter 1.NET: What Is Really Happening The assembly that is created does not contain executable code, but, rather, code in Intermediate Language, or IL (sometimes called Microsoft Intermediate Language, or MSIL). In the Windows environment, this IL code is packaged up in a standard portable executable (PE) file format, so you will see the familiar.exe extension (or, if you are building a component, the.dll extension). You can view an assembly using the ILDASM tool. When you run the.exe, a special runtime environment (the Common Language Runtime, or CLR) is launched and the IL instructions are executed by the CLR. Unlike some runtimes, where the IL would be interpreted each time it is executed, the CLR comes with a just-in-time (JIT) compiler, which translates the IL to native machine code the first time it is encountered. On subsequent calls, the code segment runs as native code. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 4

15 VbEss Chapter 1.NET Programming in a Nutshell 1. Write your program in a high-level.net language, such as Visual Basic. 2. Compile your program into IL. 3. Run your IL program, which will launch the CLR to execute your IL, using its JIT to translate your program to native code as it executes. We will look at a simple example of a Visual Basic program, and run it under.net. Don t worry about the syntax of Visual Basic, which we will start discussing in the next chapter. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 5

16 VbEss Chapter 1.NET Program Example See SimpleCalc in the Chap01 folder. 1. Enter the program in a text editor. ' SimpleCalc.vb ' ' This program does a simple calculation: calculate ' area of a rectangle Module SimpleCalc Sub Main () Dim base As Integer = 20 Dim height As Integer = 5 Dim area As Integer area = base * height System.Console.WriteLine("Area = {0}", area) End Sub End Module 2. Compile the program at the command line. Start the console window via Start All Programs Microsoft Visual Studio 2012 Visual Studio Tools Developer Command Prompt for VS2012. Navigate to the Chap01\SimpleCalc folder. >vbc SimpleCalc.vb 3. Run your IL program SimpleCalc.exe >SimpleCalc area = 100 Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 6

17 VbEss Chapter 1 Viewing the Assembly You can view the assembly using the ILDASM tool 1. >ildasm SimpleCalc.exe 1 You can change the font size from the View menu. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 7

18 VbEss Chapter 1 Viewing Intermediate Language Double-click on Main:void() Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 8

19 VbEss Chapter 1 Understanding.NET The nice thing about a high-level programming language is that you usually do not need to be concerned with the platform on which the program executes. You can work with the abstractions provided by the language and with functions provided by libraries. Your appreciation of the Visual Basic programming language and its potential for creating great applications will be richer if you have a general understanding of.net. After this course, we suggest you next study:.net Framework Using Visual Basic Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 9

20 VbEss Chapter 1 Visual Studio 2012 While it is possible to write Visual Basic programs using any text editor, and compile them with the command-line compiler, it is very tedious to program that way. An IDE makes the process of writing software much easier. An IDE provides convenience items, such as a syntaxhighlighting editor. An IDE reduces the tedium of keeping track of configurations, environment settings and file organizations. You may use Visual Studio 2012 throughout this course to create and compile your VB programs. Visual Studio 2012 is discussed in more detail in Appendix A. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 10

21 VbEss Chapter 1 Creating a Console Application We will now create a simple console application. Our program is the same simple calculator we created earlier that was compiled at the command line. 1. From the Visual Studio main menu, choose File New Project... This will bring up the New Project dialog. 2. Choose Console Application. 3. Leave.NET Framework 4.5 as the target framework. Leave checked Create directory for solution In the Name field, type SimpleCalcVs and for Location browse to C:\OIC\VbEss\Demos. Click OK. 2 Examples in later chapters frequently do not have a directory for solution. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 11

22 VbEss Chapter 1 Visual Studio Solutions In Visual Studio 2012, project information is organized by solutions and projects. A solution, specified by a.sln file, consists of one or more projects, specified by.vbproj files in the case of Visual Basic. Notice Solution Explorer in the top-right. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 12

23 VbEss Chapter 1 Starter Code We see that a Visual Studio solution has been created with one project. The project contains two elements. The folder MyProject contains a number of files that we normally will not need to touch. Module1.vb contains skeleton code that we will edit. We ve closed a few windows that we don t need at this point. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 13

24 VbEss Chapter 1 Using the Visual Studio Text Editor In Solution Explorer, change the name of the file Module1.vb to SimpleCalc.vb. Other changes will be made for you automatically, such as changing the name of the module to SimpleCalc. Make the following edits, using the Visual Studio text editor. Module SimpleCalc Sub Main() Dim base As Integer = 20 Dim height As Integer = 5 Dim area As Integer area = base * height System.Console.WriteLine("Area = {0}", area) End Sub End Module Notice that the Visual Studio text editor highlights syntax, indents automatically, and so on. In Visual Basic, as opposed to Visual C#, the editor does other things for you too, such as supply matching End keywords, adjust capitalization of keywords, and so on. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 14

25 VbEss Chapter 1 IntelliSense A powerful feature of Visual Studio is IntelliSense. IntelliSense will automatically pop up a list box allowing you to easily insert language elements directly into your code. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 15

26 VbEss Chapter 1 Build and Run the Project Building a project means compiling the individual source files and linking them together with any library files to create an IL executable.exe file. You can build the project by using one of the following: Menu Build Build Solution or toolbar button shortcut Ctrl+Shift+B. or keyboard Menu Build Build SimpleCalcVs or toolbar button just builds the project SimpleCalcVs) 3. (this You can run the program without the debugger by using one of the following: Toolbar (This toolbar button is not provided by default; see Appendix A for how to add it to your Build toolbar.) Keyboard shortcut Ctrl + F5 You can run the program in the debugger by using one of the following: Menu Debug Start Debugging Toolbar Keyboard shortcut F5 Try it! 3 The two are the same in this case, because the solution has only one project, but some solutions have multiple projects, and then there is a difference. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 16

27 VbEss Chapter 1 Pausing the Output If you run the program in the debugger from Visual Studio, you will notice that the output window automatically closes on program termination. To keep the window open, you may prompt the user for some input. Module SimpleCalc Sub Main() Dim base As Integer = 20 Dim height As Integer = 5 Dim area As Integer area = base * height System.Console.WriteLine("Area = {0}", area) System.Console.WriteLine( _ "Prese Enter to exit") System.Console.ReadLine() End Sub End Module This version of the program is saved as a Visual Studio 2012 project in Chap01\SimpleCalcVs. Remember that you can always make the console window stay open by running without the debugger via Control + F5. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 17

28 VbEss Chapter 1 Visual Basic and GUI Programs Microsoft s Visual Basic language works very effectively in a GUI environment. Using Windows Forms, it is easy to create Windows GUI programs in Visual Basic. Example: See Chap01\SimpleCalcGui We will discuss GUI programming using Visual Basic in Chapter 6. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 18

29 VbEss Chapter 1.NET Documentation MSDN documentation for the.net Framework is included with Visual Studio Use the menu Help View Help. Other menu choices let you add and remove content and to set a preference for launching in Browser or Help Viewer. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 19

30 VbEss Chapter 1 Summary As in other environments, with.net you write a program in a high-level language, compile to an executable (.EXE file), and run that.exe file. The.EXE file, called an assembly, contains Intermediate Language instructions. You can view an assembly through the ILDASM tool. Visual Studio 2012 is a powerful IDE that makes it easy to develop Visual Basic programs. With Visual Studio, it is easy to create GUI programs using Visual Basic. You can access extensive.net Framework documentation through the Visual Studio help system. Rev.4.5 Copyright 2013 Object Innovations Enterprises, LLC 20

31 VbEss Chapter 5 Chapter 5 Delegates and Events Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 195

32 VbEss Chapter 5 Delegates and Events Objectives After completing this unit you will be able to: Use delegate objects to implement callbacks. Use the Random class to generate random test data. Use aggregations of delegate objects. Use delegate objects to implement and handle event notifications. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 196

33 VbEss Chapter 5 Overview of Delegates and Events In the previous chapters we examined interfaces in some detail. One feature of interfaces is that they facilitate writing code in such a way that your program is called into by some other code. This style of programming has been available for a long time, under the guise of callback functions. In this chapter, we examine delegates in Visual Basic, which can be thought of as type-safe and objectoriented callback functions. Delegates are the foundation for a more elaborate callback protocol, known as events. Events are a cornerstone of COM, the predecessor of.net, and are widely used in Windows programming. We will study events and look at several example programs that illustrate delegates and events. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 197

34 VbEss Chapter 5 Callbacks and Delegates A callback function is one that your program specifies and registers in some way. This function is then called by another program. In C and C++, callback functions are implemented using function pointers. In Visual Basic, you can encapsulate a reference to a method inside a delegate object. A delegate can refer to either a shared method or an instance method. When a delegate refers to an instance method, it stores both an object instance and an entry point to the instance method. The instance method can then be called through this object instance. When a delegate object refers to a shared method, it stores just the entry point of this shared method. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 198

35 VbEss Chapter 5 Usage of Delegates You can then pass this delegate object to other code, which can then call your method. The code that calls your delegate method does not have to know at compile time which method is being called; it only has to know the exact signature. In Visual Basic, a delegate is considered a reference type that is similar to a class type. A new delegate instance is created just like any other class instance, using the New operator. Visual Basic delegates are implemented by the.net Framework class library as a class, derived ultimately from System.Delegate. Delegates are object-oriented and type-safe, and they enjoy the safety of the managed code execution environment. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 199

36 VbEss Chapter 5 Declaring a Delegate You declare a delegate in Visual Basic using a special notation with the keyword Delegate and the signature of the encapsulated method. Private Delegate Function Compare( _ ByVal x As Integer, ByVal y As Integer) As Boolean The Compare delegate in this example can contain a reference to any function with the return type Boolean and two parameters of type Integer. An example program illustrates sorting an array in both ascending and descending order. The choice is made according to what Compare delegate instance is used See the example program DelegateDemo. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 200

37 VbEss Chapter 5 Defining a Method When you instantiate a delegate, you will need to specify a method, which must match the signature in the delegate declaration. The method may be either a shared method or an instance method. Recalled that all methods of a module are automatically shared. Here are some examples of methods that can be hooked to the Compare delegate: Private Function LessThan(ByVal x As Integer, _ ByVal y As Integer) As Boolean If x < y Then Return True Else Return False End If End Function Private Function GreaterThan(ByVal x As Integer, _ ByVal y As Integer) As Boolean If x > y Then Return True Else Return False End If End Function Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 201

38 VbEss Chapter 5 Creating a Delegate Object You instantiate a delegate object with the New operator, just as you would with any other class. The following code illustrates creating a delegate object that is hooked to a shared method. Private Sub Ascending() Dim array As Integer() = GetArray() ' Instantiate delegate for ascending sort Dim comp As New Compare(AddressOf GreaterThan) BubbleSort(array, comp) ShowArray(array) End Sub Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 202

39 VbEss Chapter 5 Calling a Delegate You call a delegate just as you would a method. The delegate object is not a method, but it has an encapsulated method. The delegate object delegates the call to this encapsulated method, hence the name delegate. In the following code, the delegate object comp is called is called to perform a comparison of two elements while performing a sort. Private Sub BubbleSort(ByVal array As Integer(), _ ByVal comp As Compare) For i As Integer = array.length - 1 To 0 Step -1 Dim j As Integer = 0 Do While j < i If comp(array(j), array(j + 1)) Then Dim temp As Integer = array(j) array(j) = array(j + 1) array(j + 1) = temp End If j += 1 Loop Next i End Sub Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 203

40 VbEss Chapter 5 Random Number Generation The.NET Framework provides a useful class Random, in the System namespace, which can be used for generating psuedo-random numbers for simulations. There are two constructors: Public Sub New() ' uses default seed Public Sub New(ByVal Seed As Integer) ' seed is specified The default seed is based on the current date and time, resulting in a different stream of random numbers each time. By specifying a seed, you can produce a deterministic stream. Overloaded Next methods produce a random integer. Dim volume As Integer = rangen.next(1, 10) * 100 This code produces a random volume between 100 and 1000, in multiples of 100. The NextDouble method produces a random double between 0 and 1. Dim r as Double = rangen.nextdouble(); The value r is in the range: 0 <= r < 1 Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 204

41 VbEss Chapter 5 A Random Array Our program DelegateDemo generates a random array of integer test data. Module DelegateDemo Private array As Integer() Public Sub Main() InitArray() ShowArray(GetArray()) Ascending() Descending() End Sub Private Sub InitArray() Dim rand As Random = New Random() ' Random size between 5 and 10 Dim size As Integer = rand.next(5, 10) array = New Integer(size - 1) {} Dim i As Integer = 0 Do While i < size ' Random integers between 1 and 100 array(i) = rand.next(1, 100) i += 1 Loop End Sub... Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 205

42 VbEss Chapter 5 Combining Delegate Objects A powerful feature of delegates is that you can combine them, implementing an invocation list of methods. When such a delegate is called, all of the methods on the invocation list will be called in turn. The System.Delegate.Combine method can be used to combine the invocation methods of two delegate objects and the System.Delegate.Remove method removes them. The program DelegateAccount illustrates using delegates in our bank account scenario. The file Account.vb declares the delegate Notify. The Account class has an encapsulated delegate object. The file DelegateAccount.vb contains methods matching the signature of the delegate. The Main method instantiates delegate objects and adds and removes them from the encapsulated delegate object in the Account class. The Account class uses its encapsulated delegate object to invoke suitable notifications when the account is overdrawn. The Account class does not know or care which notification methods will be invoked in the case of an overdraft. It simply calls the delegate, which in turn calls all the methods on its invocation list. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 206

43 VbEss Chapter 5 Account.vb Public Delegate Sub Notify(ByVal balance As _ Decimal) Public Class Account Private balance As Decimal Public notifydlg As Notify Public Sub New(ByVal bal As Decimal) balance = bal End Sub Public Sub Deposit(ByVal amount As Decimal) balance += amount End Sub Public Sub Withdraw(ByVal amount As Decimal) balance -= amount If balance < 0 Then notifydlg(balance) End If End Sub End Class Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 207

44 VbEss Chapter 5 DelegateAccount.vb Module DelegateAccount Public Sub Main() Dim acc As New Account(100) Dim custdlg As _ New Notify(AddressOf NotifyCustomer) Dim bankdlg As _ New Notify(AddressOf NotifyBank) ' Notify customer of an overdraft acc.notifydlg = _ System.Delegate.Combine(acc.notifyDlg, custdlg) acc.withdraw(125) ' Also notify bank of an overdraft acc.notifydlg = _ System.Delegate.Combine(acc.notifyDlg, bankdlg) acc.withdraw(50) ' Remove bank notification acc.notifydlg = System.Delegate.Remove(acc.notifyDlg, bankdlg) acc.withdraw(50) End Sub Private Sub NotifyCustomer( _ ByVal balance As Decimal) Console.WriteLine("Dear customer,") Console.WriteLine( _ " Account overdrawn, balance = {0}", balance) End Sub Private Sub NotifyBank(ByVal balance As Decimal) Console.WriteLine("Dear bank,") Console.WriteLine( _ " Account overdrawn, balance = {0}", balance) End Sub End Module Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 208

45 VbEss Chapter 5 Events Delegates are the foundation for a more elaborate callback protocol known as events. Conceptually, servers implement incoming interfaces, which are called by clients. In a diagram, such an interface may be shown with a small bubble (a notation used in COM). Sometimes a client may wish to receive notifications from a server when certain events occur. The server may then specify an outgoing interface. The server defines the interface and the client implements it. In a diagram, such an interface may be shown with an arrow (again, a notation used in COM). Client Server Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 209

46 VbEss Chapter 5 Static and Dynamic Event Handling Visual Basic can support static event handling via the WithEvents keyword in a manner similar to VB6. Visual Basic also supports dynamic event handling, where event handlers can be added or removed at runtime. We will look at dynamic event handling first, because it is tied closely to the underlying delegate mechanism that we have studied. We will then discuss static event handling. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 210

47 VbEss Chapter 5 Dynamic Event Handling The.NET Framework provides an easy-to-use implementation of the event paradigm built on delegates. Visual Basic simplifies working with.net events by providing the keyword Event and the AddHandler and RemoveHandler keywords to hook up event handlers to events and to remove them. The Framework also defines a base class EventArgs to be used for passing arguments to event handlers. A number of derived classes, such as MouseEventArgs, define data members to hold appropriate argument information for specific events. An event handler is a delegate with a specific signature: Public Delegate Sub EventHandler( _ ByVal sender As Object, ByVal e As EventArgs) The name EventHandler is arbitrary. The first argument represents the source of the event, and the second argument contains data associated with the event. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 211

48 VbEss Chapter 5 Chat Room Example The chat room example in EventDemo\Step2 illustrates the complete architecture on both the server and client sides. The server declares delegates: Public Delegate Sub JoinHandler( _ ByVal sender As Object, ByVal e As ChatEventArg) Public Delegate Sub QuitHandler( _ ByVal sender As Object, ByVal e As ChatEventArg) The ChatServer class declares events based on these delegates: Public Class ChatServer Private m_members As ArrayList = New ArrayList() Public Event Join As JoinHandler Public Event Quit As QuitHandler Whenever a new member joins or quits, the server sends a notification to the client. Public Sub JoinChat(ByVal name As String) m_members.add(name) ' fire the Join event RaiseEvent Join(Me, New ChatEventArg(name)) End Sub Public Sub QuitChat(ByVal name As String) m_members.remove(name) ' fire the Quit event RaiseEvent Quit(Me, New ChatEventArg(name)) End Sub Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 212

49 VbEss Chapter 5 Chat Room Example (Cont d) The client program defines event handlers, which print out an appropriate message. Public Sub OnJoinChat(ByVal sender As Object, _ ByVal e As ChatEventArg) Console.WriteLine( _ "sender = {0}, {1} has joined the chat", _ sender, e.m_name) End Sub The Main procedure registers the event handlers. Sub Main() Dim chat As ChatServer = New ChatServer() ' Register to receive event notifications AddHandler chat.join, AddressOf OnJoinChat AddHandler chat.quit, AddressOf OnQuitChat ' Call methods on the server chat.joinchat("michael") chat.joinchat("bob") chat.joinchat("sam") chat.showmembers("after 3 have joined") chat.quitchat("bob") chat.showmembers("after 1 has quit") End Sub Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 213

50 VbEss Chapter 5 Static Event Handling Static event handling in Visual Basic is simpler but less flexible. If a class implements events, you may declare an object reference to that class using the WithEvents keyword. The Visual Basic compiler will then look for matching procedures with the Handles keyword and, under the hood, instantiate delegates and add handlers. As an example, consider EventDemo\Step3. The server program is unchanged. The client program now uses static event handling. ' ChatClient.vb ' Step3 - Static Event Handling Imports System Module ChatClient Dim WithEvents chat As ChatServer Public Sub OnJoinChat( _ ByVal sender As Object, _ ByVal e As ChatEventArg) Handles chat.join Console.WriteLine( _ "sender = {0}, {1} has joined the chat", _ sender, e.m_name) End Sub Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 214

51 VbEss Chapter 5 Static Event Handling (Cont d) Public Sub OnQuitChat( _ ByVal sender As Object, _ ByVal e As ChatEventArg) Handles chat.quit Console.WriteLine( _ "sender = {0}, {1} has quit the chat", _ sender, e.m_name) End Sub Sub Main() chat = New ChatServer("OI Chat Room") ' Don't need these AddHandler calls ' AddHandler chat.join, AddressOf OnJoinChat ' AddHandler chat.quit, AddressOf OnQuitChat ' Call methods on the server chat.joinchat("michael") chat.joinchat("bob") chat.joinchat("sam") chat.showmembers("after 3 have joined") chat.quitchat("bob") chat.showmembers("after 1 has quit") End Sub End Module Here is the output (both versions): sender = OI Chat Room, Michael has joined the chat sender = OI Chat Room, Bob has joined the chat sender = OI Chat Room, Sam has joined the chat --- After 3 have joined--- Michael Bob Sam sender = OI Chat Room, Bob has quit the chat --- After 1 has quit--- Michael Sam Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 215

52 VbEss Chapter 5 Lab 5 Implementing Events In this lab, you will study the chat room server and add code to the chat room client in order to provide event handlers and hook them to the event. You will also add code to the server in order to provide better information about the sender of the event. Detailed instructions are contained in the Lab 5 write-up at the end of the chapter. Suggested time: 30 minutes Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 216

53 VbEss Chapter 5 Summary Delegates can be thought of as type-safe and objectoriented callback functions. In Visual Basic, you can encapsulate a reference to a method inside a delegate object. You can then pass this delegate object to other code, which can call your method. The code that calls your delegate method does not have to know at compile time which method is being called. Delegates can be combined, creating an invocation list of methods. The Random class, in the System namespace, provides an easy means for generating random numbers. Delegates are the foundation for a more elaborate callback protocol, known as events. Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 217

54 VbEss Chapter 5 Introduction Lab 5 Implementing Events In this lab, you will study the chat room server and add code to the chat room client to provide event handlers and hook them to the event. You will also add code to the server to provide better information about the sender of the event. Suggested Time: 30 minutes Root Directory: OIC\VbEss Directories: Labs\Lab5\EventDemo Chap05\EventDemo\Step0 Chap05\EventDemo\Step1 Chap05\EventDemo\Step2 Chap05\EventDemo\Step3 (do your work here) (backup copy of starter files) (answer to first part) (answer to second part) (static event handling) Instructions 1. Build and run the starter project. You will see a printout showing chat room membership after three people have joined and again after one person has quit. Study the code in both the server and client. The server is fully provided with event functionality. No events are fired, because no client has hooked into any of the events. 2. In the client, add event handlers OnJoinChat and OnQuitChat with the proper signature for event handlers. They should print out the sender and also a brief message indicating who has joined or quit the chat. 3. In the Main method, add code to register these event handlers with the appropriate server events. 4. Build and run the program. You should now see that your event handlers are called every time someone joins or quits the chat. But the information about the sender is not very descriptive just the name of the class of the sender is displayed. (Step 1) 5. To get more descriptive information, add a field chatname to the ChatServer class that is initialized in the constructor. Add code in the client to provide a chat name when instantiating a ChatServer object. 6. Now add code to the server so that the chat name will be displayed, rather than the class name, when the client prints out the sender. How do you do this? Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 218

55 VbEss Chapter 5 7. You do it by overriding the ToString() method. Build and run. (Step 2) 8. If you have time, modify the client to use static event handling (WithEvents keyword) in place of dynamic event handling. (Step 3) Rev. 4.5 Copyright 2013 Object Innovations Enterprises, LLC 219

C++/CLI Essentials. Student Guide Revision 1.0. Object Innovations Course 431

C++/CLI Essentials. Student Guide Revision 1.0. Object Innovations Course 431 C++/CLI Essentials Student Guide Revision 1.0 Object Innovations Course 431 C++/CLI Essentials Rev. 1.0 Student Guide Information in this document is subject to change without notice. Companies, names

More information

Object-Oriented Programming in C# (VS 2012)

Object-Oriented Programming in C# (VS 2012) Object-Oriented Programming in C# (VS 2012) This thorough and comprehensive course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes the C#

More information

Object-Oriented Programming in C# (VS 2015)

Object-Oriented Programming in C# (VS 2015) Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes

More information

Evaluation Copy. C# Essentials. Student Guide Revision 4.5. Object Innovations Course 4102

Evaluation Copy. C# Essentials. Student Guide Revision 4.5. Object Innovations Course 4102 C# Essentials Student Guide Revision 4.5 Object Innovations Course 4102 C# Essentials Rev. 4.5 Student Guide Information in this document is subject to change without notice. Companies, names and data

More information

Student Guide Revision 1.0

Student Guide Revision 1.0 Robert J. Oberg Student Guide Revision 1.0 Object Innovations Course 411 C# Essentials Rev. 1.0 Student Guide Information in this document is subject to change without notice. Companies, names and data

More information

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C# Microsoft s.net is a revolutionary advance in programming technology that greatly simplifies application development and is a good match for the emerging paradigm of Web-based services, as opposed to proprietary

More information

Object-Oriented Programming in C# Evaluation Copy. Student Guide Revision 4.5. Object Innovations Course 4101

Object-Oriented Programming in C# Evaluation Copy. Student Guide Revision 4.5. Object Innovations Course 4101 Object-Oriented Programming in C# Student Guide Revision 4.5 Object Innovations Course 4101 Object-Oriented Programming in C# Rev. 4.5 Student Guide Information in this document is subject to change without

More information

EVALUATION COPY. Object-Oriented Programming in C# Student Guide Revision 4.6. Unauthorized reproduction or distribution is prohibited.

EVALUATION COPY. Object-Oriented Programming in C# Student Guide Revision 4.6. Unauthorized reproduction or distribution is prohibited. Object-Oriented Programming in C# Student Guide Revision 4.6 Object Innovations Course 4101 Object-Oriented Programming in C# Rev. 4.6 Student Guide Information in this document is subject to change without

More information

C# Programming in the.net Framework

C# Programming in the.net Framework 50150B - Version: 2.1 04 May 2018 C# Programming in the.net Framework C# Programming in the.net Framework 50150B - Version: 2.1 6 days Course Description: This six-day instructor-led course provides students

More information

Course Syllabus C # Course Title. Who should attend? Course Description

Course Syllabus C # Course Title. Who should attend? Course Description Course Title C # Course Description C # is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the.net Framework.

More information

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

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio Introduction XXV Part I: C# Fundamentals 1 Chapter 1: The.NET Framework 3 What s the.net Framework? 3 Common Language Runtime 3.NET Framework Class Library 4 Assemblies and the Microsoft Intermediate Language

More information

Programming in Visual Basic with Microsoft Visual Studio 2010

Programming in Visual Basic with Microsoft Visual Studio 2010 Programming in Visual Basic with Microsoft Visual Studio 2010 Course 10550; 5 Days, Instructor-led Course Description This course teaches you Visual Basic language syntax, program structure, and implementation

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

EVALUATION COPY. Unauthorized reproduction or distribution is prohibitied C# ESSENTIALS

EVALUATION COPY. Unauthorized reproduction or distribution is prohibitied C# ESSENTIALS C# ESSENTIALS C# Essentials Rev. 4.8 Student Guide Information in this document is subject to change without notice. Companies, names and data used in examples herein are fictitious unless otherwise noted.

More information

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Microsoft. Microsoft Visual C# Step by Step. John Sharp Microsoft Microsoft Visual C#- 2010 Step by Step John Sharp Table of Contents Acknowledgments Introduction xvii xix Part I Introducing Microsoft Visual C# and Microsoft Visual Studio 2010 1 Welcome to

More information

Object-Oriented Programming in Visual Basic

Object-Oriented Programming in Visual Basic Object-Oriented Programming in Visual Basic Student Guide Revision 4.0 Object Innovations Course 4201 Object-Oriented Programming in Visual Basic Rev. 4.0 Student Guide Information in this document is

More information

Microsoft Visual C# Step by Step. John Sharp

Microsoft Visual C# Step by Step. John Sharp Microsoft Visual C# 2013 Step by Step John Sharp Introduction xix PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2013 Chapter 1 Welcome to C# 3 Beginning programming with the Visual

More information

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

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Course Hours

Course Hours Programming the.net Framework 4.0/4.5 with C# 5.0 Course 70240 40 Hours Microsoft's.NET Framework presents developers with unprecedented opportunities. From 'geoscalable' web applications to desktop and

More information

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn the

More information

CHAPTER 1: INTRODUCING C# 3

CHAPTER 1: INTRODUCING C# 3 INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the.net Framework? 4 What s in the.net Framework? 4 Writing Applications Using the.net Framework 5 What Is C#? 8 Applications

More information

Object-Oriented Programming in Visual Basic

Object-Oriented Programming in Visual Basic Object-Oriented Programming in Visual Basic Dana L. Wyatt Robert J. Oberg Student Guide Revision 2.1 Object Innovations Course 420 Object-Oriented Programming in Visual Basic Rev. 2.1 Student Guide Information

More information

Programming in C# with Microsoft Visual Studio 2010

Programming in C# with Microsoft Visual Studio 2010 Programming in C# with Microsoft Visual Studio 2010 Course 10266; 5 Days, Instructor-led Course Description: The course focuses on C# program structure, language syntax, and implementation details with.net

More information

Fundamental C# Programming

Fundamental C# Programming Part 1 Fundamental C# Programming In this section you will find: Chapter 1: Introduction to C# Chapter 2: Basic C# Programming Chapter 3: Expressions and Operators Chapter 4: Decisions, Loops, and Preprocessor

More information

10266 Programming in C Sharp with Microsoft Visual Studio 2010

10266 Programming in C Sharp with Microsoft Visual Studio 2010 10266 Programming in C Sharp with Microsoft Visual Studio 2010 Course Number: 10266A Category: Visual Studio 2010 Duration: 5 days Course Description The course focuses on C# program structure, language

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

CHAPTER 1: INTRODUCTION TO THE IDE 3

CHAPTER 1: INTRODUCTION TO THE IDE 3 INTRODUCTION xxvii PART I: IDE CHAPTER 1: INTRODUCTION TO THE IDE 3 Introducing the IDE 3 Different IDE Appearances 4 IDE Configurations 5 Projects and Solutions 6 Starting the IDE 6 Creating a Project

More information

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary Course Summary NOTE - The course delivery has been updated to Visual Studio 2013 and.net Framework 4.5! Description The course focuses on C# program structure, language syntax, and implementation details

More information

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

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank Unit 1 Introduction to.net Platform Q: 1 Answer in short. 1. Which three main components are available in.net framework? 2. List any two new features added in.net framework 4.0 which is not available in

More information

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Course Number: 2555 Length: 1 Day(s) Certification Exam This course will help you prepare for the following Microsoft Certified Professional

More information

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

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class. 1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Learning C# 3.0 Jesse Liberty and Brian MacDonald O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Table of Contents Preface xv 1. C# and.net Programming 1 Installing C# Express 2 C# 3.0

More information

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net Objective of the Course: (Why the course?) To provide a brief introduction to the.net platform and C# programming language constructs. Enlighten the students about object oriented programming, Exception

More information

Learning to Program in Visual Basic 2005 Table of Contents

Learning to Program in Visual Basic 2005 Table of Contents Table of Contents INTRODUCTION...INTRO-1 Prerequisites...INTRO-2 Installing the Practice Files...INTRO-3 Software Requirements...INTRO-3 Installation...INTRO-3 Demonstration Applications...INTRO-3 About

More information

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13 contents preface xv acknowledgments xvii about this book xix PART 1 THE C++/CLI LANGUAGE... 1 1 Introduction to C++/CLI 3 1.1 The role of C++/CLI 4 What C++/CLI can do for you 6 The rationale behind the

More information

Variable Scope The Main() Function Struct Functions Overloading Functions Using Delegates Chapter 7: Debugging and Error Handling Debugging in Visual

Variable Scope The Main() Function Struct Functions Overloading Functions Using Delegates Chapter 7: Debugging and Error Handling Debugging in Visual Table of Contents Title Page Introduction Who This Book Is For What This Book Covers How This Book Is Structured What You Need to Use This Book Conventions Source Code Errata p2p.wrox.com Part I: The OOP

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Computer programming: creating a sequence of instructions to enable the computer to do something Programmers do not use machine language when creating computer programs. Instead, programmers tend to

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

C# Syllabus. MS.NET Framework Introduction

C# Syllabus. MS.NET Framework Introduction C# Syllabus MS.NET Framework Introduction The.NET Framework - an Overview Framework Components Framework Versions Types of Applications which can be developed using MS.NET MS.NET Base Class Library MS.NET

More information

DOT NET Syllabus (6 Months)

DOT NET Syllabus (6 Months) DOT NET Syllabus (6 Months) THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In- Time Compilation and CLS Disassembling.Net Application to IL

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

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

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 1. Which language is not a true object-oriented programming language? A. VB 6 B. VB.NET C. JAVA D. C++ 2. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. both (a)

More information

Introducing C# and the.net Framework

Introducing C# and the.net Framework 1 Introducing C# and the.net Framework C# is a general-purpose, type-safe, object-oriented programming language. The goal of the language is programmer productivity. To this end, the language balances

More information

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

C# Programming: From Problem Analysis to Program Design. Fourth Edition C# Programming: From Problem Analysis to Program Design Fourth Edition Preface xxi INTRODUCTION TO COMPUTING AND PROGRAMMING 1 History of Computers 2 System and Application Software 4 System Software 4

More information

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

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500 Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500 Summary Each day there will be a combination of presentations, code walk-throughs, and handson projects. The final project

More information

[CHAPTER] 1 INTRODUCTION 1

[CHAPTER] 1 INTRODUCTION 1 FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32 Contents 1 2 3 Contents Getting started 7 Introducing C# 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a Console project 14 Writing your first program 16 Following the rules 18 Summary 20

More information

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Chapter 12 OOP: Creating Object- Oriented Programs McGraw-Hill Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Objectives (1 of 2) Use object-oriented terminology correctly. Create

More information

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET Chapter. 03 9/17/01 6:08 PM Page 35 Visual Studio.NET T H R E E Although it is possible to program.net using only the command line compiler, it is much easier and more enjoyable to use Visual Studio.NET.

More information

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com 70-483 MCSA Universal Windows Platform A Success Guide to Prepare- Programming in C# edusum.com Table of Contents Introduction to 70-483 Exam on Programming in C#... 2 Microsoft 70-483 Certification Details:...

More information

Saikat Banerjee Page 1

Saikat Banerjee Page 1 1. What s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each

More information

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS Core Java SYLLABUS COVERAGE Introduction. OOPS Package Exception Handling. Multithreading Applet, AWT, Event Handling Using NetBean, Ecllipse. Input Output Streams, Serialization Networking Collection

More information

"Charting the Course to Your Success!" MOC B Programming in C# Course Summary

Charting the Course to Your Success! MOC B Programming in C# Course Summary Course Summary Description This training course teaches developers the programming skills that are required for developers to create Windows applications using the C# language. During their five days in

More information

The Microsoft.NET Framework

The Microsoft.NET Framework Microsoft Visual Studio 2005/2008 and the.net Framework The Microsoft.NET Framework The Common Language Runtime Common Language Specification Programming Languages C#, Visual Basic, C++, lots of others

More information

Overview of the Ruby Language. By Ron Haley

Overview of the Ruby Language. By Ron Haley Overview of the Ruby Language By Ron Haley Outline Ruby About Ruby Installation Basics Ruby Conventions Arrays and Hashes Symbols Control Structures Regular Expressions Class vs. Module Blocks, Procs,

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop. 2016 Spis treści Preface xi 1. Introducing C# and the.net Framework 1 Object Orientation 1 Type Safety 2 Memory Management

More information

Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started

Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started Developing Desktop Apps for Ultrabook Devices in Windows 8*: Getting Started By Paul Ferrill The Ultrabook provides a rich set of sensor capabilities to enhance a wide range of applications. It also includes

More information

DOT NET SYLLABUS FOR 6 MONTHS

DOT NET SYLLABUS FOR 6 MONTHS DOT NET SYLLABUS FOR 6 MONTHS 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.) CLR Architecture and Services The.Net Intermediate

More information

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

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net UNIT 1 Introduction to Microsoft.NET framework and Basics of VB.Net 1 SYLLABUS 1.1 Overview of Microsoft.NET Framework 1.2 The.NET Framework components 1.3 The Common Language Runtime (CLR) Environment

More information

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2 Worksheet #2 Overview For this worksheet, we will create a class library and then use the resulting dynamic link library (DLL) in a console application. This worksheet is a start on your next programming

More information

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Course Number: 6367A Course Length: 3 Days Course Overview This three-day course will enable students to start designing

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

C# Language. CSE 409 Advanced Internet Technology

C# Language. CSE 409 Advanced Internet Technology C# Language Today You will learn Building a basic class Value Types and Reference Types Understanding Namespaces and Assemblies Advanced Class Programming CSE 409 Advanced Internet Technology Building

More information

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23 Contents 1 2 3 Getting started 7 Introducing Visual Basic 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects

More information

Hands-On Lab. Lab Manual HOL007 Understanding, Designing, and Refactoring Code Using the New Class Designer Tool in Microsoft Visual Studio 2005

Hands-On Lab. Lab Manual HOL007 Understanding, Designing, and Refactoring Code Using the New Class Designer Tool in Microsoft Visual Studio 2005 Hands-On Lab Lab Manual HOL007 Understanding, Designing, and Refactoring Code Using the New Class Designer Tool in Microsoft Visual Studio 2005 Please do not remove this manual from the lab Page 1 Information

More information

C++/CLI in Action NISHANT SIVAKUMAR MANNING. Greenwich (74 w. long.)

C++/CLI in Action NISHANT SIVAKUMAR MANNING. Greenwich (74 w. long.) C++/CLI in Action NISHANT SIVAKUMAR 11 MANNING Greenwich (74 w. long.) brief contents PART 1 THE C++/CLI LANGUAGE 1 1 IntroductiontoC++/CLI 3 2 Getting into the CLI: properties, delegates and arrays 46

More information

Chapters are PDF documents posted online at the book s Companion Website (located at

Chapters are PDF documents posted online at the book s Companion Website (located at vbhtp6printonlytoc.fm Page ix Wednesday, February 27, 2013 11:59 AM Chapters 16 31 are PDF documents posted online at the book s Companion Website (located at www.pearsonhighered.com/deitel/). Preface

More information

Murach s Beginning Java with Eclipse

Murach s Beginning Java with Eclipse Murach s Beginning Java with Eclipse Introduction xv Section 1 Get started right Chapter 1 An introduction to Java programming 3 Chapter 2 How to start writing Java code 33 Chapter 3 How to use classes

More information

The C# Programming Language. Overview

The C# Programming Language. Overview The C# Programming Language Overview Microsoft's.NET Framework presents developers with unprecedented opportunities. From web applications to desktop and mobile platform applications - all can be built

More information

Getting Started with Web Services

Getting Started with Web Services Getting Started with Web Services Getting Started with Web Services A web service is a set of functions packaged into a single entity that is available to other systems on a network. The network can be

More information

20483BC: Programming in C#

20483BC: Programming in C# 20483BC: Programming in C# Course length: 5 day(s) Course Description The goal of this course is to help students gain essential C# programming skills. This course is an entry point into the Windows Store

More information

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

Unit 1: Visual Basic.NET and the.net Framework 1 Chapter1: Visual Basic.NET and the.net Framework Unit 1: Visual Basic.NET and the.net Framework Contents Introduction to.net framework Features Common Language Runtime (CLR) Framework Class Library(FCL)

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at Contents Chapters 16 27 and Appendix F are PDF documents posted online at the book s Companion Website (located at www.pearsonhighered.com/deitel/). Preface Before You Begin xix xxix 1 Introduction to

More information

1 OBJECT-ORIENTED PROGRAMMING 1

1 OBJECT-ORIENTED PROGRAMMING 1 PREFACE xvii 1 OBJECT-ORIENTED PROGRAMMING 1 1.1 Object-Oriented and Procedural Programming 2 Top-Down Design and Procedural Programming, 3 Problems with Top-Down Design, 3 Classes and Objects, 4 Fields

More information

M Introduction to C# Programming with Microsoft.NET - 5 Day Course

M Introduction to C# Programming with Microsoft.NET - 5 Day Course Module 1: Getting Started This module presents the concepts that are central to the Microsoft.NET Framework and platform, and the Microsoft Visual Studio.NET integrated development environment (IDE); describes

More information

Department of Computer Applications

Department of Computer Applications MCA 512:.NET framework and C# [Part I : Medium Answer type Questions] Unit - 1 Q1. What different tools are available and used to develop.net Applications? Hint a).net Framework SDK b) ASP.NET Web Matrix

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

DC69 C# &.NET DEC 2015

DC69 C# &.NET DEC 2015 Q.2 a. Briefly explain the advantage of framework base classes in.net. (5).NET supplies a library of base classes that we can use to implement applications quickly. We can use them by simply instantiating

More information

After completing this appendix, you will be able to:

After completing this appendix, you will be able to: 1418835463_AppendixA.qxd 5/22/06 02:31 PM Page 879 A P P E N D I X A A DEBUGGING After completing this appendix, you will be able to: Describe the types of programming errors Trace statement execution

More information

Table of Contents Preface Bare Necessities... 17

Table of Contents Preface Bare Necessities... 17 Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17

More information

C# Programming. Unit 1: Introducing C# and the.net FrameworkThis module explains the.net Framework, and using C# and

C# Programming. Unit 1: Introducing C# and the.net FrameworkThis module explains the.net Framework, and using C# and C# Programming 1. Sound Knowledge of C++. Course Summary: This course presents Microsoft's C# programming language and the use of Visual Studio 2008 or 2010 to develop Windows applications using the.net

More information

PES INSTITUTE OF TECHNOLOGY

PES INSTITUTE OF TECHNOLOGY Seventh Semester B.E. IA Test-I, 2014 USN 1 P E I S PES INSTITUTE OF TECHNOLOGY C# solution set for T1 Answer any 5 of the Following Questions 1) What is.net? With a neat diagram explain the important

More information

"Charting the Course... Java Programming Language. Course Summary

Charting the Course... Java Programming Language. Course Summary Course Summary Description This course emphasizes becoming productive quickly as a Java application developer. This course quickly covers the Java language syntax and then moves into the object-oriented

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

Procedures in Visual Basic

Procedures in Visual Basic Procedures in Visual Basic https://msdn.microsoft.com/en-us/library/y6yz79c3(d=printer).aspx 1 of 3 02.09.2016 18:50 Procedures in Visual Basic Visual Studio 2015 A procedure is a block of Visual Basic

More information

Creating and Running Your First C# Program

Creating and Running Your First C# Program Creating and Running Your First C# Program : http://eembdersler.wordpress.com Choose the EEE-425Programming Languages (Fall) Textbook reading schedule Pdf lecture notes Updated class syllabus Midterm and

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 Creating and Running Your First C# Program : http://eembdersler.wordpress.com Choose the EEE-425Programming Languages (Fall) Textbook reading schedule Pdf lecture notes Updated class syllabus Midterm and

More information

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the

More information

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline :: Module Title Duration : Intro to JAVA SE7 and Programming using JAVA SE7 : 9 days Course Description The Java SE 7 Fundamentals course was designed to enable students with little or no programming experience

More information

Visual Basic 2008 Anne Boehm

Visual Basic 2008 Anne Boehm TRAINING & REFERENCE murach s Visual Basic 2008 Anne Boehm (Chapter 3) Thanks for downloading this chapter from Murach s Visual Basic 2008. We hope it will show you how easy it is to learn from any Murach

More information

WA1278 Introduction to Java Using Eclipse

WA1278 Introduction to Java Using Eclipse Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA1278 Introduction to Java Using Eclipse This course introduces the Java

More information

Oracle 10g: Java Programming

Oracle 10g: Java Programming Oracle 10g: Java Programming Volume 1 Student Guide D17249GC12 Edition 1.2 July 2005 D19367 Author Kate Heap Technical Contributors and Reviewers Ken Cooper Brian Fry Jeff Gallus Glenn Maslen Gayathri

More information

3 Getting Started with Objects

3 Getting Started with Objects 3 Getting Started with Objects If you are an experienced IDE user, you may be able to do this tutorial without having done the previous tutorial, Getting Started. However, at some point you should read

More information

2609 : Introduction to C# Programming with Microsoft.NET

2609 : Introduction to C# Programming with Microsoft.NET 2609 : Introduction to C# Programming with Microsoft.NET Introduction In this five-day instructor-led course, developers learn the fundamental skills that are required to design and develop object-oriented

More information