Access object programmatically in c#

  • Let's say I've got two objects that are named Thing1 and Thing2. I would like to, in C# code, be able to loop through these objects and apply the same logic to each. Obviously, the loop logic would have to construct the name on the fly (like "Thing" + x, where x = 1 during the first iteration, x = 2 during the second iteration, etc.). But I haven't found a way to get this to work.


  • What you are trying to do is use something like the eval() function found in JS/AS. You cannot do that in C#, but what you can do is store your objects in an array or list and iterate through that list and deal with each object individually.

    Now, if you have an arbitrarily large amount of objects, then it seems a bit tedious to add each object to a list. What you can do in those cases, is place those objects inside their own parent control/panel/etc. Let's say your panel is called "Foo", and you can use Foo.Children to get all of the child elements inside foo, add them to your list, and iterate through that list later.

    :)







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Access object programmatically in c# , Please add it free.