Q: Use a method that returns a delegate to authorized callers. How? Im learning C#. There is a question in a book (Exam Ref 70-483) which makes little sence to me, because I can't find any examples of it anywhere. I understand it in terms of eliminating the wrong answers and the right answer must be there. 


*

*You have a private method in your class and you want to make invocation of the method possible by certain callers. What do you do?


A.  Make the method public.
B.  Use an event so outside users can be notified when the method is executed.
C.  Use a method that returns a delegate to authorized callers.
D.  Declare the private method as a lambda.
Correct answer 'C': "The method can see whether the caller is authorized and then return a delegate to the private method that can be invoked at will."
What is an example of this? What do they mean by authorized caller? There is no mention of authorized caller in the book. The only thing I could find about delegate and method authorization was about WCF and authorization, but that is for sure out of scope here. Well. I hope someone could shed some light on this! There are so many tough questions like this... well if not tough questions, difficult to understand answers.

A: Here's an example of how answer C can be implemented.
class Conspirator
{
    private void SecretMethod()
    {
        Console.WriteLine("Secret exposed!");
    }

    public Action GetSecretMethod(long authorizationKey)
    {
        if (authorizationKey == 63278823982)
        {
            return this.SecretMethod;
        }

        return null;
    }
}

As you see, SecretMethod is private. GetSecretMethod returns a delegate containing a reference to the private method, but only if the authorizationKey passed is correct. Of course, this is a very basic form of "authorization" and in real life you would have some other mechanism of authorization.
You use this class in the following way:
void Main()
{
    var conspirator = new Conspirator();

    var secretPrinter = conspirator.GetSecretMethod(63278823982);
    secretPrinter();
    // Prints "Secret exposed!"
}


A: The answers are really vague, and the 'correct' answer doesn't make sense in terms of architecture. 'Authorized caller' doesn't really make sense without context. But, we can approach it by process of elimination.   


*

*Make the method public  


This lets everyone call it, so it's wrong.


*Use an event so outside users can be notified when the method is executed.  


This has nothing to do with invoking the method, it's just a distraction of an answer. Wrong  


*Use a method that returns a delegate to authorized callers.  


If we assume that 'authorized callers' means 'certain callers', then this is a possibility.


*Declare the private method as a lambda.  


This is a part of what you'd do to restrict access to the method, but doesn't actually do anything. So, it doesn't solve the problem.  
So #3 (or C) is correct. This question is really a bad question, and there isn't really a clear answer. The 'answer' is essentially the same as what the question is, with no further detail.  
For your question about an 'authorized caller', it's not specified (which is the problem I have with this question, too). There's nothing you're able to research other than to take the answer verbatim (not in a technical sense). As I said, the answer is essentially the same as the question, which is not really an answer. I'd equate it to "What is 1 + 1 ? Answer: 1 + 1"
