Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting up properties that are generic lists

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I am setting up a generic list of SqlParameters:

private List<SqlParameter> _params;

I will be adding the SqlParameters from a method:

Code:
            List<SqlParameter> parameters = new List<SqlParameter>()
                {
                    database.SetParameter("@RoleID", SqlDbType.Int, roleID),
                    database.SetParameter("@Description", SqlDbType.VarChar,50, description)
                };

where SetParameter returns a parameter.

How do I set List<SqlParameter> up as a property to allow the above initial setup and a normal adding parameter the way you would a normal list?

parameters.Add(database.SetParameter("@UserID", SqlDbType.Int, userID));

Normally, I would do something like:

Code:
        private List<SqlParameter> _params; 
        public List<SqlParameter> Params
        { 
            get{ return _params}; 
            set( ; ?????
        }

Thanks,

Tom
 
I got it.

I couldn't get it to work but found someone that said you have to create and instance in the constructor. But it turns out you only have to set up the instance when you set up the private variable:

Code:
        private List<SqlParameter> _parameters = new List<SqlParameter>(); 
        public List<SqlParameter> Parameters
        { 
            get{ return _parameters;}
            set { _parameters = value; } 
        }

Now I just use my normal handling of the list.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top