B
batatoon
Hi, I could use some help with this because I've run out of ideas.
I need to sort an arraylist containg objects of type TA, but so far no
luck.
Here's the code:
Class TAList: ArrayList {
normal arraylist methods...
.... add
.... remove
public TA Item(int i) {
if (_tacol.Count==0) {
throw new InvalidOperationException("Nothing available.");
} else if (i<=_tacol.Count) {
return((TA)_tacol);
} else {
return(null);
}
}
}
Class TA {
public int ID = 0;
}
Class NTA: TA, IComparable {
private double m_STLI = 0;
public double STLI{
get{return(m_STLI);}
set{m_STLI =value;}
}
// returns:
// -1 if is less than x
// 0 if matches x
// 1 if is greater than x
public int CompareTo(object obj) {
if (obj is NTA) {
return this.m_STLI.CompareTo(((NTA)obj).STLI);
} else {
throw new ArgumentException("Object is not of type NTA");
}
}
}
class TAManager {
private TAList m_objTAList=null;
public TAList taList {
get {return(m_objTAList);}
set {m_objTAList=value;}
}
}
class NManager: TAManager {
public void LoadNTA() {
string sql = "select x,y,z from ta";
ArrayList al = DB.GetArrayList(DBType.SqlServer,sql);
foreach (object[] row in al) {
NTA nta = new NTA();
nta.ID = Convert.ToInt32(row[0]);
taList.Add(nta);
}
}
public double CalcLI() {
int icount = this.taList.Count;
if (icount>0) {
//input values
for (int i=0;i<icount;i++) {
NTA nta = (NTA)this.taList.Item(i);
nta.STLI = STLI();
}
taList.Sort(); //<--- FAILS HERE!!!
}
}
}
I get the following error message:
"Offset and length were out of bounds for the array or count is greater
than the number of elements from index to the end of the source
collection."
but I can't find what is it that I'm doing wrong. Please help !
Thank you
I need to sort an arraylist containg objects of type TA, but so far no
luck.
Here's the code:
Class TAList: ArrayList {
normal arraylist methods...
.... add
.... remove
public TA Item(int i) {
if (_tacol.Count==0) {
throw new InvalidOperationException("Nothing available.");
} else if (i<=_tacol.Count) {
return((TA)_tacol);
} else {
return(null);
}
}
}
Class TA {
public int ID = 0;
}
Class NTA: TA, IComparable {
private double m_STLI = 0;
public double STLI{
get{return(m_STLI);}
set{m_STLI =value;}
}
// returns:
// -1 if is less than x
// 0 if matches x
// 1 if is greater than x
public int CompareTo(object obj) {
if (obj is NTA) {
return this.m_STLI.CompareTo(((NTA)obj).STLI);
} else {
throw new ArgumentException("Object is not of type NTA");
}
}
}
class TAManager {
private TAList m_objTAList=null;
public TAList taList {
get {return(m_objTAList);}
set {m_objTAList=value;}
}
}
class NManager: TAManager {
public void LoadNTA() {
string sql = "select x,y,z from ta";
ArrayList al = DB.GetArrayList(DBType.SqlServer,sql);
foreach (object[] row in al) {
NTA nta = new NTA();
nta.ID = Convert.ToInt32(row[0]);
taList.Add(nta);
}
}
public double CalcLI() {
int icount = this.taList.Count;
if (icount>0) {
//input values
for (int i=0;i<icount;i++) {
NTA nta = (NTA)this.taList.Item(i);
nta.STLI = STLI();
}
taList.Sort(); //<--- FAILS HERE!!!
}
}
}
I get the following error message:
"Offset and length were out of bounds for the array or count is greater
than the number of elements from index to the end of the source
collection."
but I can't find what is it that I'm doing wrong. Please help !
Thank you