Alex Rivera | Logout

In 3 minutes, What is Reflection?

Asked 2009-12-07T13:14:49.723
44

Many .Net interview question lists (including the good ones) contain the question: "What is Reflection?". I was recently asked to answer this in the context of a 5 question, technical test designed to be completed in 15 minutes on a sheet of blank paper handed to me in a cafeteria. My answer went along the lines of "Reflection allows you to discover the Methods, Properties and Fields of any object at runtime". In retrospect, my answer explains how you can use reflection, but it does not explain what reflection is. In my view, my answer was sufficient to convey that I understand what reflection is for but didn't go so far as to explain what reflection is.

So please, in the context of .Net, in your own concise words, define what Reflection is. Don't spend more than three minutes answering. Don't refer to the .Net documentation, we've all seen it.

Edit
Report

2 Answers

9

Reflection is the CLR's awareness of code-level objects such class names, methods, etc. that is exposed via an API, namely System.Reflection, which allows a developer to leverage the runtime's cognizance of this information in their code.

Rule violation: I've edited this answer from its original form for the sake of accuracy.

answered 2009-12-07T13:19:05.113
4

I like your answer but I would also mention that Reflection is also a way of getting/setting private/protected fields/properties, that would otherwise not be available at runtime.

answered 2009-12-07T13:19:45.097

Your Answer