{ "response": { "questions": [ { "question": "What is an anonymous method in C#?", "answer": "An anonymous method is a method that does not have a name and can be defined inline within a delegate or expression tree. It provides a concise way to pass code as a parameter without defining a separate named method." }, { "question": "How do you declare an anonymous method in C#?", "answer": "You can declare an anonymous method using the `delegate` keyword followed by the return type and parameters of the method. For example: `NumberChanger nc = delegate(int x) { Console.WriteLine(\"Anonymous Method: {0}\", x); };`" }, { "question": "What is the difference between a named method and an anonymous method in C#?", "answer": "A named method has a name defined outside of the scope where it is used, whereas an anonymous method does not have a name and is defined inline within a delegate or expression tree." }, { "question": "When should you use an anonymous method in C#?", "answer": "Anonymous methods are useful when you need to pass a small block of code as a parameter without defining a separate named method. They can be used for simple operations that do not need to be reused elsewhere." }, { "question": "Can an anonymous method have multiple statements in its body?", "answer": "Yes, an anonymous method can have multiple statements in its body. The statements are enclosed within curly braces `{}` and must end with a semicolon `;` after the last statement." } ] } }