Understanding Reflection and static constructor


Hi .net newbies, This post is mostly for you !!, to understand what Reflection and static constructor really mean ,and when are they used in .net projects. This is a simple post which teaches you Reflection and static constructor in a real time coding.

You would have learnt what does .net reflection and static constructor mean:

You may say reflection is :
The process of obtaining information about the assemblies and the types defined within them ,and creating and invoking and accessing type instance at run time and
You may say static constructor is:
used to initialize any static data or to perform a certain action that needs to be performed once.

So when do you use Reflection or static constructor in your current project , the below picture answers the question:


Reflection and Static

The above code logs Error and Information of a project, it uses the power of reflection and static constructor


You can see the static methods because you are going to use it like this: Logging.WriteError(), and you don't need to create new object and waste memory for it.

You use reflection in WriteError() , to show where the error actually occurred, i.e from which Method the error/exception occurred.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: