S
SpotNet
Hello NewsGroup,
I have a custom class and a collection for that custom class that inherits
CollectionBase. As such;
public class MyClass
{
private string datamember1 = string.Empty, datamember2 = string.Empty;
private int datamember3 = -1;
public MyClass(string dataMember1) {this.datamember1 = dataMember1;}
public void AGreatFunction() {//The usual stuff}
public bool TrueOrFalse(string argument) {return false;}
public string DataMember1
{get {return this.datamember1;}
}//public class MyClass
public class MyClassCollection: CollectionBase
{
public MyClass this[int index] //How well this works
{
set {this.List[index] = value;}
get {return (MyClass) this.List[Index];}
}
public MyClass this[string classKey] //This doesn't work
{
set {this.List[this.List.IndexOf(classKey)] = value;}
get {return (MyClass) this.List[this.List.IndexOf(classKey)];}
}
}//public class MyClassCollection: CollectionBase
This string indexer doesn't work as 'this.List.IndexOf(classKey)' always
returns -1. Can someone tell me please what I must consider to get a string
indexer working for this situation? Many thanks news group.
Regards,
SpotNet.
I have a custom class and a collection for that custom class that inherits
CollectionBase. As such;
public class MyClass
{
private string datamember1 = string.Empty, datamember2 = string.Empty;
private int datamember3 = -1;
public MyClass(string dataMember1) {this.datamember1 = dataMember1;}
public void AGreatFunction() {//The usual stuff}
public bool TrueOrFalse(string argument) {return false;}
public string DataMember1
{get {return this.datamember1;}
}//public class MyClass
public class MyClassCollection: CollectionBase
{
public MyClass this[int index] //How well this works
{
set {this.List[index] = value;}
get {return (MyClass) this.List[Index];}
}
public MyClass this[string classKey] //This doesn't work
{
set {this.List[this.List.IndexOf(classKey)] = value;}
get {return (MyClass) this.List[this.List.IndexOf(classKey)];}
}
}//public class MyClassCollection: CollectionBase
This string indexer doesn't work as 'this.List.IndexOf(classKey)' always
returns -1. Can someone tell me please what I must consider to get a string
indexer working for this situation? Many thanks news group.
Regards,
SpotNet.