Declare a class or struct inside a method

.net, c#

Solution

You can create an anonymous type like so:

var x = new { x = 10, y = 20 };

but other than that: no.

Problem

In C#, is it possible to declare a class or struct inside a method, as in C++? e.g. C++: ``` void Method() { class NewClass { } newClassObject; } ``` I have tried, but it's not allowing me to do so.

Original source