indexed properties : Indexer « Class Interface « C# / C Sharp






indexed properties

 

using System;

public class Starter {
    public static void Main() {
        Names obj = new Names();
        Console.WriteLine(obj[1]);
    }
}

public class Names {
    object[,] _names ={{"V", 27},{"B", 35},{"D", 29}};

    public object this[int index] {
        get {
            return _names[index, 0] + " " + _names[index, 1];
        }
    }
}

 








Related examples in the same category

1.Indexer with complex logic
2.Use an indexer to create a fail-soft arrayUse an indexer to create a fail-soft array
3.Overload the FailSoftArray indexerOverload the FailSoftArray indexer
4.Indexers don't have to operate on actual arraysIndexers don't have to operate on actual arrays
5.Two dimensional indexer
6.A two-dimensional fail-soft arrayA two-dimensional fail-soft array
7.Create a specifiable range array classCreate a specifiable range array class
8.Define indexerDefine indexer
9.Indexer: allow array like indexIndexer: allow array like index
10.illustrates the use of an indexer 1illustrates the use of an indexer 1
11.Implements an indexer in a classImplements an indexer in a class
12.Illustrates the use of an indexer
13.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
14.C# Properties and Indexers
15.Indexing with an Integer IndexIndexing with an Integer Index
16.Indexing with an String Index
17.Indexing with Multiple ParametersIndexing with Multiple Parameters
18.Return class object from indexer