This documentation is archived and is not being maintained.

PropertyInfo.GetIndexParameters Method

When overridden in a derived class, returns an array of all the index parameters for the property.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public abstract ParameterInfo[] GetIndexParameters ()
public abstract ParameterInfo[] GetIndexParameters ()
public abstract function GetIndexParameters () : ParameterInfo[]
Not applicable.

Return Value

An array of type ParameterInfo containing the parameters for the indexes.

Extract any required parameter information from the returned array.

To use the GetIndexParameters method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetIndexParameters method.

The following example displays the index parameters of the specified property.

using System;
using System.Reflection;
 
// A class that contains some properties.
public class MyProperty   
{
    // Define a simple string property.
    private string caption = "A Default caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption = value;}
        }
    }

    // A very limited indexer that gets or sets one of four 
    // strings.
    private string[] strings = {"abc", "def", "ghi", "jkl"};
    public string this[int Index]    
    {
        get
        {
            return strings[Index];
        }
        set
        {
            strings[Index] = value;
        }
    }
}
 
class Mypropertyinfo
{
    public static int Main()
    {
        // Get the type and PropertyInfo.
        Type t = Type.GetType("MyProperty");
        PropertyInfo pi = t.GetProperty("Caption");
 
        // Get the public GetIndexParameters method.
        ParameterInfo[] parms = pi.GetIndexParameters();
        Console.WriteLine("\r\n" + t.FullName + "." + pi.Name
            + " has " + parms.GetLength(0) + " parameters.");
 
        // Display a property that has parameters. The default 
        // name of an indexer is "Item".
        pi = t.GetProperty("Item");
        parms = pi.GetIndexParameters();
        Console.WriteLine(t.FullName + "." + pi.Name + " has " + 
            parms.GetLength(0) + " parameters.");
        foreach( ParameterInfo p in parms )
        {
            Console.WriteLine("   Parameter: " + p.Name);
        }

        return 0;
    }
}
/*
 This example produces the following output:
 MyProperty.Caption has 0 parameters.
 MyProperty.Item has 1 parameters.
    Parameter: Index
 */

import System.*;
import System.Reflection.*;

// A class that contains some properties.
public class MyProperty
{
    // Define a simple string property.
    private String caption = "A Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption
    /** @property 
     */
    public void set_Caption ( String value )
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
   
    // A very limited indexer that gets or sets one of four 
    // strings.
    private String strings[] =  {"abc", "def", "ghi", "jkl"};
    /** @property 
     */
    public String get_Item(int Index)
    {
        return strings[Index] ;
    } //get_Item
    /** @property 
     */
    public void set_Item (int Index,String value)
    {
        strings[Index] = value;
    } //set_Item
} //MyProperty

class MyPropertyInfo
{   
    public static void main(String[] args)
    {
        // Get the type and PropertyInfo.
        Type t = Type.GetType("MyProperty");
        PropertyInfo pi = t.GetProperty("Caption");

        // Get the public GetIndexParameters method.
        ParameterInfo parms[] = pi.GetIndexParameters();
        Console.WriteLine(("\r\n" + t.get_FullName() + "." + pi.get_Name() 
            + " has " + parms.GetLength(0) + " parameters."));

        // Display a property that has parameters. The default 
        // name of an indexer is "Item".
        pi = t.GetProperty("Item");
        parms = pi.GetIndexParameters();
        Console.WriteLine((t.get_FullName() + "." + pi.get_Name() + " has " 
            + parms.GetLength(0) + " parameters."));

        for(int iCtr=0; iCtr< parms.length; iCtr++) {
            ParameterInfo p = parms[iCtr];
            Console.WriteLine(("   Parameter: " + p.get_Name()));
        }
    } //main
} //MyPropertyInfo
/*
This example produces the following output:
MyProperty.Caption has 0 parameters.
MyProperty.Item has 1 parameters.
Parameter: Index
*/

import System;
import System.Reflection;
 
//Make a property
 public class Myproperty   
 {
    private var caption : String = "A Default caption";
    public function get Caption() : String {
        return caption;
    }
    public function set Caption(value:String) {
        if(caption!=value) caption = value;
    }
 }
 
 class Mypropertyinfo
 {
    public static function Main() : void
       {
       Console.WriteLine ("\nReflection.PropertyInfo");
 
       //Get the type and PropertyInfo
       var MyType : Type = Type.GetType("Myproperty");
       var Mypropertyinfo : PropertyInfo = MyType.GetProperty("Caption");
 
       //Get the public GetIndexParameters Method
       var Myparameterinfoarray : ParameterInfo[] =
          Mypropertyinfo.GetIndexParameters();
       Console.Write ("\n" + MyType.FullName + "." + Mypropertyinfo.Name
          + " has " + Myparameterinfoarray.GetLength(0) + " parameters");
     }
 }
 Mypropertyinfo.Main();
 /*
 Produces the following output
 
 Reflection.PropertyInfo
 Myproperty.Caption has 0 parameters
 */

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: