what is the wrong with this implementation of Comparable<T>

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello!

I have the following simple program below.
What is the problem when I get runtime error for
"Failed to compare two elements in the array ?"

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
list.Add(new Person("tony", 13));
list.Add(new Person("olle", 23));
list.Add(new Person("stina", 53));
list.Add(new Person("august", 3));
list.Add(new Person("roland", 33));

foreach (Person pers in list)
Console.WriteLine(pers.Age);

list.Sort();
foreach (Person pers in list)
Console.WriteLine(pers.Age);
}
}

public class Person : IComparable<Person>
{
string name;
int age;

public Person(string lname, int lage)
{
name = lname;
age = lage;
}

public int Age
{
set {age = value;}
get {return age; }
}

public int CompareTo(Person other)
{
return this.Age - other.Age;
}
}
}


//Tony


.



Relevant Pages

  • Re: Annotations processing + type introspection + code generation
    ... You define interface, the tool tries to guess what you ... long savePerson(String name, int age); ... Then tool defines final class PersonDaoImpl and PersonImpl: ... private final int age; ...
    (comp.lang.java.programmer)
  • Re: how to return Comparator values
    ... public int compare{ ... positive or zero. ... public Double getAge() ... A name Comparator would be similar, but use a different implementation of the comparemethod, one based on getNameinstead of getAge ...
    (comp.lang.java.help)
  • Re: signed and unsigned
    ... > earth” explanation about signed and unsigned and more likely in few ... int age; ... unsigned int age; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to use getline()?
    ... cin>> age; ... getline(cin, sName); ...
    (microsoft.public.vc.language)
  • Re: 2 initializers in 1 constructor
    ... other way round - make B(int age) call B ... default value) and make B(string name, int age) call base. ... The other constructors, the ones with fewer parameters, call the ...
    (microsoft.public.dotnet.languages.csharp)