C#: how to get an object by the name stored in String?

Solution 1:

No, it's not.

Objects don't have names - variables do. An object may be referenced by any number of variables: zero, one or many.

What you can do, however, is get fields (static or instance variables) by name (using Type.GetField) and get the values of those fields (for a specific instance, if you're using instance variables).

Depending on what you're trying to do, you might also want to consider a dictionary from names to objects.

Solution 2:

No, not all objects have a Name property (for starters).

But you can store objects of interest in a Dictionary<string, object>. You could also get a Control by name, the exact method would depend on the UI library.