Arrays VB.NET 2010. Declaring Arrays Dim Salary(15) As Integer ‘ 16 Elements Salary(15) = 10000 for each s as Integer in Salary Console.WriteLine( s.toString(

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

CS 141 Computer Programming 1 1 Arrays. Outline  Introduction  Arrays  Declaring Arrays  Examples Using Arrays  Sorting Arrays  Multiple-Subscripted.
LINQ and Collections An introduction to LINQ and Collections.
1. Penulisan array yang benar adalah : double[] myList; myList = new double[10];  Array with myList has variable dimension 10  Index begin from 0 till.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
Introduction to C# Properties, Arrays, Loops, Lists Game Design Experience Professor Jim Whitehead January 28, 2008 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Arrays. Declaring a Array With subscript: –Dim numbers(2) as Integer –Using variable as subscript: Dim arrayIndex as Integer = 10 Dim myArray(arrayIndex)
JAVA 1.5 New Features Dr V. The syntax of the enhanced for loop (for each) for (type variableName : arrayName) { statements } arrayName could be any.
A String T h e Q u i c k B r o w n F o x 0 str char str[100]; strcpy(str, “The Quick Brown Fox”);
Chapter 7: Working with Arrays
7.1 Arrays Introduction to arrays Any array is a collection of objects or primitives Useful when the number of reference variables is large or.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
CIS 280 Hashing and Hash Tables. Calendar Today: Hashing and Hash Tables Wednesday: Calculus due, work Friday: Cuckoo hashing and linear hashing Monday:
AP Comp Sci A Chapter 12 - Arrays. Ch 12 Goals: Goals: Declare and create arrays Declare and create arrays Access elements in arrays Access elements in.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
LISTS AND ARRAYS CHAPTER Topics  C# Collections  List –Flexible collection of variable length  Array –Standard arrays  Multidimensional Arrays.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
Arrays and Collections Tonga Institute of Higher Education.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Arrays An array is a list or series of values all referenced by the same name Also referred to as a table An element is an individual item in the array.
CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
 An array stores multiple values in one single variable.  Example: Output: I like Honda Civic, BMW and Toyota.
CS 116: Object Oriented Programming II. Topics Vectors Multidimensional Arrays ArrayList.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
Computing with C# and the .NET Framework
CHAPTER 22 LISTS AND ARRAYS 1.
Introduction to Programming Lecture 5
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
A1 Student Posters Posters Print Services  Robinson Library  University of Newcastle  phone: Introduction The.
<ELLIIT Project Name>
Introduction To Programming Information Technology , 1’st Semester
Can store many of the same kind of data together
Object Oriented Programming in java
Poster Title Heading Heading Heading Heading Heading Heading
Compiler Design Second Lecture.
Managing Collections of Data
A0 PowerPoint Poster Posters at Print Services Robinson Library, Newcastle University • • phone Introduction.
2016 REPORT.
Classes and Objects VB.net.
Basic Collections.
A1 Student Posters Posters at Print Services  Robinson Library  University of Newcastle  phone: Introduction.
目 录 The quick brown fox. 目 录 The quick brown fox.
Arrays.
2016 REPORT.
Presentation transcript:

Arrays VB.NET 2010

Declaring Arrays Dim Salary(15) As Integer ‘ 16 Elements Salary(15) = for each s as Integer in Salary Console.WriteLine( s.toString( “Rs #.00”) ) next Dim Names( ) As String = {“Joe”, “Peter “}

SORTING ARRAYS System.array.Sort( arrayName ) System.array.Sort( arrayName, startIndex, endIndex ) System.array.Sort( array1, array2 )

SEARCHING ARRAYS i = System.array.IndexOf( arrayName, Object ) i = System.array.IndexOf( arrayName, Object, startIndex) i = System.array.IndexOf( arrayName, Object, startIndex, endIndex ) i = System.array.BinarySearch( arrayName, Object ) i = System.array.BinarySearch( arrayName, startIndex, searchLength, Object ) -i – 1 ‘ one’s complement

ARRAYS... newArraay = System.array.Reverse( array1) System.array.copy( array1, array2, count ) System.array.copyto(destinationArray, sourceStart) ◦ Both Copy and Copyto are one dimensional only System.array.copy( sourceArray, sourceStart, destinationArray, destinationStart, count )

Structures Structure Employee Dim Name As String Dim Salary As Decimal Dim DOB as Date End Structure Dim E1 as New Employee E1.DOB = #01/31/2000#

Multidimensional Arrays Temperatures(2, 0) ‘ is the third city’s name Temperatures(2, 1) ‘ is the third city’s temperature

Multidimensional Arrays... Dim a(,) As Integer = {{10, 20, 30}, {11, 21, 31}, {12, 22, 32}} Console.WriteLine(a(0, 1)) ’ will print 20 Console.WriteLine(a(2, 2)) ’ will print 32 To find out the number of dimensions : a.Rank’ will print 2

Multidimensional Arrays... Console.WriteLine(a.GetLength(1)) ’ # of elements in second dimension = 3 Console.WriteLine(a.Length) ’ total elements = 9 Console.WriteLine(a.GetUpperBound(0)) ’ last index in the first dimension = 2 Console.WriteLine(a.GetLowerBound(1)) ’ first index in the second dimension = 3

LIST Dim names As New List(Of String) Dim colors As New List(Of Color) names.Add(“Richard”) names.Add(“Nancy”) colors.Add(Color.Red) colors.Add(TextBox1.BackColor) If names.Contains(name) Then MsgBox("Duplicate ")

Iterating Through a List For i = 0 To Lst.Count - 1 { process item Lst(i)} Next For Each itm As String In Lst ’ process item lst Next Dim itm As Object For Each itm In aLst { process item itm } Next

Dictionary Dim BDays As New Dictionary(Of String, Date) BDays.Add(“Manfred”, #3/24/1972#) ‘ Key & Value BDays.Add(“Alfred”, #11/24/1959#) To retrieve the birth date of Manfred, use the following statement: BDays(“Manfred”)

Dictionary.. Dictionary.ContainsKey(object) Dictionary.ContainsValue(object) Dim itm As Object For Each itm In Dict.Values Debug.WriteLine(itm) Next

HashTable Dim tmps As New Hashtable tmps("Houston") = 81.3 tmps("Los Angeles") = 78.5

ArrayList Dim aList As New ArrayList ‘ Don’t need to define the type as in LIST aList.capacity = 100 aList.Insert(index, object) Lst.AddRange(colors) Lst.InsertRange(index, objects) Lst.SetRange(5, words) ‘overwrite

ArrayList... aList.Remove(object) Lst.RemoveRange(startIndex, count) newLst = Lst.GetRange(index, count) newList = ArrayList.Repeat(item, count) newList = aList.Repeat(item, count) newList = System.arrayList.Repeat(item, count)

ArrayList... newList = aList.Revese() newList = aList.Revese(startIndex, endIndex) Sorting and Searching are same as in Arrays

Collection Initializers Dim letters As New ArrayList ( {"quick", "dog", "fox", "lazy", "brown"}) Dim words = New List(Of String) ( {"the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog“ } ) Dim numbers() As Decimal = {2.0, 12.99, 0.001, , 10.01} Dim P = New With {.First = "Evangelos",.Last = "Petroutsos"} ‘P is of an anonymous type

Sorting Lists aLst.Sort() aLst.Sort(comparer) aLst.Sort(startIndex, endIndex, comparer)

SortedList Dim sList As New SortedList Dim sList As New SortedList(New comparer) sList.Add(key, item)

Searching Lists Lst.IndexOf(object) Lst.IndexOf(object, startIndex) Lst.IndexOf(object, startIndex, length) Dim index As Integer = Lst.BinarySearch(object) Dim index As Integer = Lst.BinarySearch(object, comparer) Dim index As Integer = Lst.BinarySearch (startIndex, length, object, comparer)

Implementing the IComparer Interface Class customComparer : Implements IComparer Public Function Compare( ByVal o1 As Object, ByVal o2 As Object) As Integer Implements IComparer.Compare { function’s code Return -1, 0 and 1 } End Function End Class

Implementing the IComparer Interface... Dim CompareThem As New customComparer aList.Sort(CompareThem) aList.Sort(New customComparer) aList.BinarySearch(object, New customComparer)

File Handling Dim str As StreamReader = File.OpenText(path) Dim txtLine As String Dim words() As String Dim Delimiters() As Char = { CType(" ", Char), CType(".", Char), CType(",", Char), CType("?", Char), CType("!", Char), CType(";", Char), CType(":", Char), Chr(10), Chr(13), vbTab } txtLine = str.ReadToEnd words = txtLine.Split(Delimiters)