Mega Code Archive

 
Categories / C# / Reflection
 

Returns the value of the property with optional index values for indexed properties

using System; using System.Reflection; class Example {     public static void Main()     {         string test = "abcdefghijklmnopqrstuvwxyz";         PropertyInfo pinfo = typeof(string).GetProperty("Chars");         object[] indexArgs = { 6 };         object value = pinfo.GetValue(test, indexArgs);         Console.WriteLine(value);         for (int x = 0; x < test.Length; x++)         {             Console.Write(pinfo.GetValue(test, new Object[] {x}));         }     } }