How to change string to property name?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeLouch Fenette
    New Member
    • Aug 2011
    • 16

    How to change string to property name?

    I want to change the string name to property name..
    for example
    Code:
    public class Code
    {
    public int RD{get;set;}
    
    public Code()
    {
       GetCode();
    }
    
    private void GetCode()
    {
    string cd= "RD";
    cd=1; // cd represent to property name "RD" 
    }
    
    }
  • rekedtechie
    New Member
    • Feb 2012
    • 51

    #2
    Code:
    public class code
    {
    public int RD { get; set; }
    }
    
    public class CodeProgram
    {
    public static void main()
    {
    code cd = new code();
    cd.RD=1;
    Console.Write{"{0}",cd.RD);
    }
    }
    Last edited by rekedtechie; Apr 24 '12, 03:41 AM. Reason: more specific

    Comment

    • RhysW
      New Member
      • Mar 2012
      • 70

      #3
      rekedtechie all that does it write the string to the console, which isn't even close to what he wants, i'm assuming from his description he wants to be able to type in a string and have that string used to create a property with the inputted string as its name, unfortunately i don't think this is even possible to do.

      During runtime the program runs the code that it already has, you can't add more to it or take it away, can i ask WHY you are trying to make a specific name for a property? perhaps if we understand more about what you are doing we can provide other ways to do it.

      RhysW

      Comment

      Working...