From: GiJeet on 3 May 2010 13:09 Hello, is it possible to have a List<whatever> as a property of a class or must you use indexers? If so, please show me an example of the syntax. Thanks. G
From: Harlan Messinger on 3 May 2010 13:17 GiJeet wrote: > Hello, is it possible to have a List<whatever> as a property of a > class or must you use indexers? If so, please show me an example of > the syntax. Thanks. It is possible to have a property, or any number of properties, of type List<whatever> in a class. public class Foo { public List<string> List1 { ... } public List<FileInfo> List2 { ... } } .... Foo foo = new Foo(); .... string firstString = foo.List1[0]; FileInfo firstFile = foo.List2[0]; This has nothing directly to do with creating indexers on Foo. But you can use a field of a list type as the implementation of an indexer.
From: GiJeet on 3 May 2010 14:27 I was looking for properties using get/set. And how to assign the list via the constructor? Example: //trying to create a list that's a property of a class holding IP addresses of a computer private List<string> lIPAddressList; internal List<string> IPAddressList { get { return lIPAddressList; } set { lIPAddressList = value; } } //The constructor of the class internal CustomException( ) { this.sUserName = Environment.UserName; this.sDomainName = Environment.UserDomainName; this.sComputerName = Dns.GetHostName(); // what to assign the whole list to a property //this.lIPAddress = Dns.GetHostEntry(ComputerName).AddressList; //what to put here? } It's just a lit of strings. Could be an array or List<string> or whatever, just need to assign to a collection.
From: Harlan Messinger on 3 May 2010 15:25 GiJeet wrote: > I was looking for properties using get/set. And how to assign the > list via the constructor? > > Example: > > //trying to create a list that's a property of a class holding IP > addresses of a computer > private List<string> lIPAddressList; > internal List<string> IPAddressList { > get { return lIPAddressList; } > set { lIPAddressList = value; } > } > > > //The constructor of the class > internal CustomException( ) { > this.sUserName = Environment.UserName; > this.sDomainName = Environment.UserDomainName; > this.sComputerName = Dns.GetHostName(); > > // what to assign the whole list to a property > //this.lIPAddress = > Dns.GetHostEntry(ComputerName).AddressList; //what to put here? > > } > > It's just a lit of strings. Could be an array or List<string> or > whatever, just need to assign to a collection.
From: Harlan Messinger on 3 May 2010 15:26 GiJeet wrote: > I was looking for properties using get/set. And how to assign the > list via the constructor? > > Example: > > //trying to create a list that's a property of a class holding IP > addresses of a computer > private List<string> lIPAddressList; > internal List<string> IPAddressList { > get { return lIPAddressList; } > set { lIPAddressList = value; } > } > > > //The constructor of the class > internal CustomException( ) { > this.sUserName = Environment.UserName; > this.sDomainName = Environment.UserDomainName; > this.sComputerName = Dns.GetHostName(); > > // what to assign the whole list to a property > //this.lIPAddress = > Dns.GetHostEntry(ComputerName).AddressList; //what to put here? > > } If AddressList is of type List<string> then this is fine. > > It's just a lit of strings. Could be an array or List<string> or > whatever, just need to assign to a collection.
|
Next
|
Last
Pages: 1 2 Prev: LdapMembershipProvider Next: SqlMembeshipProvider.Initialize name parameter |