INT422 Internet III Web Programming on Windows - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

INT422 Internet III Web Programming on Windows

Description:

Data type is up to you integer, string, or object. INT422. 4. Arrays ... Collections support a number of easy-to-use and common methods and properties ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 14
Provided by: team61
Category:

less

Transcript and Presenter's Notes

Title: INT422 Internet III Web Programming on Windows


1
INT422 Internet III Web Programming on
Windows
  • Arrays and Collections

2
Arrays
3
Arrays
  • Named data storage structure
  • Multiple elements
  • Zero-based
  • A 10-element array of strings is declared
    asstring studentNames new string10
  • Data type is up to you integer, string, or
    object

4
Arrays declaring and using
  • Declare string array with 5 elements
  • //Build an array of five strings
  • //Remember - .NET indexes are zero-based
  • //Array elements start at index 0
  • string sa new string5
  • int i 0
  • for(i 0 ilt 5 i)
  • sai "Element " i.ToString()

5
Arrays declaring (continued)
  • Another syntax
  • 'Build an array of five strings
  • 'Remember - .NET indexes are zero-based
  • 'Array elements start at index 0
  • string sa new string5
  • "Zero, "One, "Two, "Three, Four

6
Collections
7
Collections
  • Collection is a generic data container
  • A group of related similarly typed objects
  • Collections store objects dynamically in memory
    and can grow or shrink at run-time
  • Used frequently throughout the BCL
  • Various types of Collections are defined in the
    System.Collections namespace
  • Tip Collections offer more power and efficiency
    than Arrays for many common tasks

8
Collections - contents
  • Collections contain other objects
  • Since everything is an Object in .NET, everything
    can be placed in a Collection, including
    Integers, Strings, objects, or even other
    collections

9
Collections examples
  • Examples
  • Controls collection the collection of all the
    Control objects that appear in a form
  • ListItems collection the collection of all the
    ListItem objects that appear in a list (e.g.
    drop-down list)
  • TableRow collection the collection of all the
    TableRow objects that appear in a data table

10
Methods supported by collections
  • Collections support a number of easy-to-use and
    common methods and properties
  • For the examples that follow, assume that a
    drop-down list control called ddlcourses
    exists, n is an integer var, and name is a
    string var
  • Examples
  • Add ddlcourses.Items.Add(INT422)
  • Count n ddlcourses.Items.Count.ToString()
  • Clear ddlcourses.Items.Clear()
  • SelectedItem name ddlcourses.SelectedItem.Text

11
Why do we need to know this?
  • Many of the controls on the ASP.NET user
    interface are list controls
  • A list control is a collection of list item
    objects
  • You typically build list items programmatically
    from values you calculate, or from values you get
    from a data file, or a database

12
Example create a course list
  • Heres an example that creates a list of courses
    programmatically (the name of the drop-down list
    control is ddlCourses)
  • //Build the ddlCourses drop-down list
  • ddlCourses.Items.Add("INT422")
  • ddlCourses.Items.Add("DCN455")
  • ddlCourses.Items.Add("EAC397")
  • ddlCourses.Items.Add("SYS466")
  • ddlCourses.Items.Add("JAC444")

13
Example create a list of file names
  • Heres an example that creates a list of file
    names found in the C\TEMP folder (the name of
    the drop-down list control is ddlFiles you
    will learn about file I/O soon)
  • string files Directory.GetFiles("c\temp")
  • foreach(string filename in files)
  • ddlFiles.Items.Add(filename)
Write a Comment
User Comments (0)
About PowerShow.com