Indexing with an Integer Index : Indexer « Class Interface « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Class Interface » IndexerScreenshots 
Indexing with an Integer Index
Indexing with an Integer Index

/*
A Programmer's Introduction to C# (Second Edition)
by Eric Gunnerson

Publisher: Apress  L.P.
ISBN: 1-893115-62-3
*/

// 19 - Indexers and Enumerators\Indexing with an Integer Index
// copyright 2000 Eric Gunnerson
using System;
using System.Collections;
class DataValue
{
    public DataValue(string name, object data)
    {
        this.name = name;
        this.data = data;
    }
    public string Name
    {
        get
        {
            return(name);
        }
        set
        {
            name = value;
        }
    }
    public object Data
    {
        get
        {
            return(data);
        }
        set
        {
            data = value;
        }
    }
    string    name;
    object data;
}
class DataRow
{
    public DataRow()
    {
        row = new ArrayList();
    }
    
    public void Load() 
    {
        /* load code here */ 
        row.Add(new DataValue("Id"5551212));
        row.Add(new DataValue("Name""Fred"));
        row.Add(new DataValue("Salary"2355.23m));
    }
    
    // the indexer
    public DataValue this[int column]
    {
        get
        {
            return((DataValuerow[column - 1]);
        }
        set
        {
            row[column - 1= value;
        }
    }
    ArrayList    row;    
}
public class IndexingwithanIntegerIndex
{
    public static void Main()
    {
        DataRow row = new DataRow();
        row.Load();
        Console.WriteLine("Column 0: {0}", row[1].Data);
        row[1].Data = 12;    // set the ID
    }
}
           
       
Related examples in the same category
1.indexed properties
2.Indexer with complex logic
3.Use an indexer to create a fail-soft arrayUse an indexer to create a fail-soft array
4.Overload the FailSoftArray indexerOverload the FailSoftArray indexer
5.Indexers don't have to operate on actual arraysIndexers don't have to operate on actual arrays
6.Two dimensional indexer
7.A two-dimensional fail-soft arrayA two-dimensional fail-soft array
8.Create a specifiable range array classCreate a specifiable range array class
9.Define indexerDefine indexer
10.Indexer: allow array like indexIndexer: allow array like index
11.illustrates the use of an indexer 1illustrates the use of an indexer 1
12.Implements an indexer in a classImplements an indexer in a class
13.Illustrates the use of an indexer
14.Implements an indexer and demonstrates that an indexer does not have to operate on an arrayImplements an indexer and demonstrates that an indexer does not have to operate on an array
15.C# Properties and Indexers
16.Indexing with an String Index
17.Indexing with Multiple ParametersIndexing with Multiple Parameters
18.Return class object from indexer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.