Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to created object referenced by a string

how to created object referenced by a string

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swheat
    wrote on last edited by
    #1

    Does any one know how to do this? I want to set object y equal to object x. I only know the name of x because it's name is contained in someString. object x = new object(); string someString = "x"; // string set to object name //problem is here: object y = (the object whose name is contained in the variable someString i.e. "x") In case you are wondering why I need such a thing.... In my app someString is actually looked up in a table. It's a long story, as usual.

    K C 2 Replies Last reply
    0
    • S swheat

      Does any one know how to do this? I want to set object y equal to object x. I only know the name of x because it's name is contained in someString. object x = new object(); string someString = "x"; // string set to object name //problem is here: object y = (the object whose name is contained in the variable someString i.e. "x") In case you are wondering why I need such a thing.... In my app someString is actually looked up in a table. It's a long story, as usual.

      K Offline
      K Offline
      knodark
      wrote on last edited by
      #2

      maybe... same type object can just matching... under follow... object x = new object(); object y = x; r u wanna that? or the other means?

      .. knodark

      1 Reply Last reply
      0
      • S swheat

        Does any one know how to do this? I want to set object y equal to object x. I only know the name of x because it's name is contained in someString. object x = new object(); string someString = "x"; // string set to object name //problem is here: object y = (the object whose name is contained in the variable someString i.e. "x") In case you are wondering why I need such a thing.... In my app someString is actually looked up in a table. It's a long story, as usual.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        REflection is what you need, if you have the name of the variable as a string and need to get the variable.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        S 1 Reply Last reply
        0
        • C Christian Graus

          REflection is what you need, if you have the name of the variable as a string and need to get the variable.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          S Offline
          S Offline
          swheat
          wrote on last edited by
          #4

          Can you point me to a keyword or something I plug into google to get more specific info? Thanks

          E 1 Reply Last reply
          0
          • S swheat

            Can you point me to a keyword or something I plug into google to get more specific info? Thanks

            E Offline
            E Offline
            echuck66
            wrote on last edited by
            #5

            Reflection, reflection, reflection... cycle through the objects and compare the object names against your string.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups