Private Variable Access Example In C#

using System;
namespace  Access_Private_Member
{
    class Program
    {
        static void Main(string[] args)
        {
            ExampleOne one = new ExampleOne();
        }
    }
    public class private_class
    {
        private string message = "You May Access Me Also";
    }
    public class ExampleOne : private_class
    {
        public ExampleOne()
        {
            System.Reflection.FieldInfo receivedObject = typeof(private_class).GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)[0];
            var obj = receivedObject.GetValue(this);
            Console.WriteLine("Access the private member using Reflection \n "+obj.ToString());
        }
    }
}

Output


Comments

Popular posts from this blog

my reframce

Angular UI Grid To Bind JSON Data