Click here to Skip to main content
15,867,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public class ClassObject
    {
        private int _Number;
        private bool _YesNo;
        private string _Word;

        public ClassObject()
        {
            _Number = 8;
            _YesNo = false;
            _Word = string.Empty;
        }

        public int Number
        {
            get { return _Number; }
            set { _Number = value; }
        }

        public bool YesNo
        {
            get { return _YesNo; }
            set { _YesNo = value; }
        }

        public string Word
        {
            get { return _Word; }
            set { _Word = value; }
        }
}


What I have tried:

C#
private Type _T; // wat should i put instead of Type

        public Type TypeClass
        {
            get
            {
                return _T;
            }

            set
            {
                _T = value;
            }
        }


this my contructor
Posted
Updated 10-Jul-16 19:03pm
v2
Comments
PIEBALDconsult 11-Jul-16 0:16am    
That doesn't look like a constructor. You have not specified your question properly. Please use "Improve question" to add context and detail.
Dave Kreskowiak 11-Jul-16 0:19am    
What constructor? The only constructor you have in your code snippets is "public ClassObject()" and I don't think you're going to pass an instance of ClassObject to itself.

What you have in the second code snippet is a Property, not a constructor.

Your "question" doesn't make any sense at all and isn't answerable.

1 solution

First, _T is private and you can only set it within the class it is defined in, use the TypeClass property instead.

Second, when you have Type fields/properties you can use :
C#
   TypeClass = typeof(myobject); // in the case where you know in the source code what the type is
// or
   TypeClass = myobj.GetType(); // where you don't know at compile time the type of the object
 
Share this answer
 
Comments
Beginner Luck 11-Jul-16 2:21am    
I got the answer but thank is same your

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900