Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Accessing Values Using Reflection in C#

$
0
0

Hi Guys,

I have this code:

using System;
using System.Collections.Generic;
namespace ConvertedCs
{
	public partial class Test
	{
            public byte flag = 0; 
            public byte index = 0; 
            public byte[] TABLE = new byte[10];

        public void Function() 
        {
            TABLE [0] = (byte)2;
            TABLE [1] = (byte)125;
            TABLE [2] = (byte)1;
            TABLE [3] = (byte)120;
            TABLE [4] = (byte)0;
            TABLE [5] = (byte)100;
            TABLE [6] = (byte)40;
            TABLE [7] = (byte)115;
            TABLE [8] = (byte)0;
            TABLE [9] = (byte)127;
        }
}

I want to access its values using reflection.

I am using this before:

FieldInfo[] fieldInfoArray = _classInstance.GetType().GetFields();
FieldInfo inputFieldInfo = _classInstance.GetType().GetField("TABLE");

And gets the value, only if the values are set when the variable was instantiated.

How can I do this? 

Thanks


Viewing all articles
Browse latest Browse all 31927

Trending Articles