locked
Generic placeholder for an object RRS feed

  • Question

  • Is there a way to create a private field of some generic type such that later you want to convert it to specific custom type?  Sort of like a placeholder private field?
    C# Web Developer
    Friday, February 5, 2010 4:11 PM

Answers

  • private Object obj;
    • Proposed as answer by Rudedog2 Friday, February 5, 2010 5:21 PM
    • Marked as answer by Ji.Zhou Thursday, February 11, 2010 2:45 AM
    Friday, February 5, 2010 4:32 PM

All replies

  • private Object obj;
    • Proposed as answer by Rudedog2 Friday, February 5, 2010 5:21 PM
    • Marked as answer by Ji.Zhou Thursday, February 11, 2010 2:45 AM
    Friday, February 5, 2010 4:32 PM
  • Or even wrap it up inside of a class so that you can modify the wrapper class without affecting clients.


        class PlaceHolder
        {
            public object Instance
            {
                get;
                set;
            }
        }


    This could be used like this in JediJohn82's example.

    private PlaceHolder obj;


    Rudy  =8^D

    Mark the best replies as answers. "Fooling computers since 1971."
    Friday, February 5, 2010 5:24 PM
  • Out of curiosity - what is the purpose of this private field?

    Tom Shelton
    Friday, February 5, 2010 6:20 PM