ASP. NET - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

ASP. NET

Description:

Jagged Array. Array Properties. Subroutines & Functions. Parameters ... Jagged ... Jagged Arrays. Another type of multidimensional array, Jagged Array, is ... – PowerPoint PPT presentation

Number of Views:224
Avg rating:3.0/5.0
Slides: 14
Provided by: Rah487
Category:
Tags: asp | net | jagged

less

Transcript and Presenter's Notes

Title: ASP. NET


1
ASP. NET
Lecture-4
2
Agenda
  • Arrays
  • Single Dimension Array
  • Multidimensional Array
  • Jagged Array
  • Array Properties
  • Subroutines Functions
  • Parameters
  • Optional
  • ParamArray

3
Arrays
  • Arrays are programming constructs that store data
    and allow us to access them by numeric index or
    subscript.
  • An array is a reference type that contains
    variables accessed through indices corresponding
    in a one-to-one fashion with the order of the
    variables in the array.
  • The variables contained in an array, also called
    the elements of the array, must all be of the
    same type, and this type is called the element
    type of the array.
  • All arrays in VB as zero based, meaning, the
    index of the first element is zero and they are
    numbered sequentially.
  • You must specify the number of array elements by
    indicating the upper bound of the array.
  • The upper bound is the number that specifies the
    index of the last element of the array.

4
Dimensioning Arrays
  • While dimensioning arrays you can
  • Call the array's constructor implicitly or
    explicitly.
  • Specify an initial size for each dimension or
    leave the initial size unspecified.
  • Initialize the elements of the array or not.
  • Most general way to declare an array

Dim Arrayname(X) as ltArray_Typegt
5
Dimensioning Arrays
  • CASE 1
  • Dim myArr( ) As Integer
  • Dim myArr() As integer New Integer()
  • Dim myArr( ) As Integer New Integer(6)
  • Dim myArr() As Integer New Integer(6)
    1,2,3,4,5,6,7
  • Dim myArr() 1,2,3,4,5,6,7
  • Imp
  • Upperbound of Array is limited to 264 -1 elements
  • For array declared with explicit bounds, explicit
    declaration is not allowed

6
Multidimensional Arrays
  • Type of Multidimensional Arrays
  • Rectangle Arrays
  • Jagged Arrays
  • Rectangle Arrays
  • Rectangular arrays are arrays in which each
    member of each dimension is extended in each
    other dimension by the same length.
  • e.g.
  • Dim rectarray2(1, 3) As Integer
  • For i 0 To 1
  • For j 0 To 3
  • rectarray2(i, j) i j
  • Next
  • Next

7
Multidimensional Arrays
  • Jagged Arrays
  • Another type of multidimensional array, Jagged
    Array, is an array of arrays in which the length
    of each array can differ.
  • e.g.
  • Dim jaggedarray(3)() As Integer
  • jaggedarray(0) New Integer() 1, 2, 3,
    4, 5
  • jaggedarray(1) New Integer() 6, 7
  • jaggedarray(3) New Integer() 8, 9, 10,
    11
  • NOTE There are NO elements for jaggedarray(2)

8
Array Properties
  • Finding Upperbound of Array
  • Arr_name.getUpperbound(index)
  • e.g.
  • myArr.getLowerBound(0) find the upperbound of
    array myArr
  • Finding Length of Array
  • Arr.Length
  • e.g.
  • myArr.Length find the length of array myArr
  • Sorting Array
  • Array.Sort(myArr)
  • e.g.
  • Array.Sort(myArr.Length)

9
Array Properties
  • Searching in an Array
  • Array.BinarySearch(myArr, item_to_be_searched) as
    integer
  • e.g.
  • Dim res Array.BinarySearch(ex2, 4)
  • Response.Write("Found at " res)
  • Reversing an Array
  • Array.Reverse(myArr)
  • e.g.
  • Array.Reverse(ex2)
  • Get value of a perticular Index
  • myArr.getValue(index) as object
  • e.g.
  • Dim d myarr.getValue(4)
  • Dim d myArr.getValue(1,1)

10
Functions/Subroutines
  • Syntax
  • e.g.
  • Private Function Cal_Area(Byval rad as single)
  • Dim area as single
  • area radrad3.14
  • Cal_Area area Same as return area
  • End Function

ltAccess_Specifiergt Function ltfunction_namegt(
Optional ByVal/ByRef param_1 as ltObjectgt
value) Function body End Function
11
Functions/Subroutines
  • Optional
  • The Optional keyword is used for parameters that
    are not required to be supplied when calling a
    function.
  • When a parameter is declared as Optional, all
    parameters after it must also be Optional.
  • You must also supply a default value for the
    parameter. So that in case optional parameters
    are not passed, there default values can be used
    upon.

12
Functions/Subroutines
  • ParamArray
  • ParamArray parameters are always passed by value
  • The parameters in the array may be of any data
    type.
  • e.g.
  • Private Function Add(ByVal ParamArray args As
    Integer()) As Integer        Dim i As
    Integer        Dim final As Integer        For
    Each i In args            final i       
    Next        Return final
  •     End Function

13
Questions???
Write a Comment
User Comments (0)
About PowerShow.com