Monday 11 August 2014

Reflection in C#

Hi
friends here i am going to give you basic idea about reflection.

Reflection:

 Reflection provides objects (of type Type) that describe assemblies, modules and types.
You can use reflection to dynamically create an instance of a type, bind the type to an existing object,
or get the type from an existing object and invoke its methods or access its fields and properties.
If you are using attributes in your code, reflection enables you to access them.


Eg:

using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class reflection
    {
        public void refs()
        {
            int i = 42;
            System.Type type = i.GetType();
            Console.WriteLine(type);

            System.Reflection.Assembly info = typeof(System.Int32).Assembly;
            Console.WriteLine(info);
        }
    }
}


Output


No comments:

Post a Comment