It works like that:
>>> def foo(arg):
... x = 1
... print locals()
...
>>> foo(7)
{'arg': 7, 'x': 1}
>>> foo('bar')
{'arg': 'bar', 'x': 1}
And i need something like this in c# .net, or how is it possible to implement it myself?
This is not possible. The other answers have given you ideas on how you can retrieve the set of local variables and their types, but certainly not their current values at time of execution. There is no provision for this in C# or .NET. The same goes for method parameters: you can retrieve their types (and even their names), but not their values.
Please allow me to suggest that if you need this, your code design is severely flawed. You should consider rethinking your code structure.
As a workaround, you could declare a class which has fields instead of the locals you want. Then you can use Reflection to iterate over those fields:
However, I think you can easily see that this is not very robust code: any time you make a change to that class, implicit assumptions you made in this code snippet might break.
The standard, recommended way to pass associative data around in C# is a
Dictionary<,>. This is the equivalent to Python’sdict. You can use aDictionary<string, object>if you need names as keys and arbitrary objects as values, but you will benefit from compile-time validity checks if you use a more specific type thanobject.