Indexing with Multiple Parameters : Indexer « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » IndexerScreenshots 
Indexing with Multiple Parameters
Indexing with Multiple Parameters

/*
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 Multiple Parameters
// copyright 2000 Eric Gunnerson
using System;

class Player
{
    string name;
    
    public Player(string name)
    {
        this.name = name;
    }
    
    public override string ToString()
    {
        return(name);
    }
}

class Board
{
    Player[,board = new Player[88];
    
    int RowToIndex(string row)
    {
        string temp = row.ToUpper();
        return((inttemp[0(int'A');
    }
    
    int PositionToColumn(string pos)
    {
        return(pos[1'0' 1);
    }
    
    public Player this[string row, int column]
    {
        get
        {
            return(board[RowToIndex(row), column - 1]);
        }
        set
        {
            board[RowToIndex(row), column - 1= value;
        }
    }    
    
    public Player this[string position]
    {
        get
        {
            return(board[RowToIndex(position),
            PositionToColumn(position)]);
        }
        set
        {
            board[RowToIndex(position),
            PositionToColumn(position)] = value;
        }
    }    
}

public class IndexingwithMultipleParameters
{
    public static void Main()
    {
        Board board = new Board();
        
        board["A"4new Player("White King");
        board["H"4new Player("Black King");
        
        Console.WriteLine("A4 = {0}", board["A"4]);
        Console.WriteLine("H4 = {0}", board["H4"]);
    }
}

           
       
Related examples in the same category
1. Use an indexer to create a fail-soft arrayUse an indexer to create a fail-soft array
2. Overload the FailSoftArray indexerOverload the FailSoftArray indexer
3. Indexers don't have to operate on actual arraysIndexers don't have to operate on actual arrays
4. A two-dimensional fail-soft arrayA two-dimensional fail-soft array
5. Create a specifiable range array classCreate a specifiable range array class
6. Define indexerDefine indexer
7. Indexer: allow array like indexIndexer: allow array like index
8. illustrates the use of an indexer 1illustrates the use of an indexer 1
9. Implements an indexer in a classImplements an indexer in a class
10. Illustrates the use of an indexer
11. 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
12. C# Properties and Indexers
13. Indexing with an Integer IndexIndexing with an Integer Index
14. Indexing with an String Index
w___w_w___._ja__va2_s_.___c___o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.