Thanks Dave for your answer,
I still wonder how i can sort the list based on the comparison of "a"
values
I mean
private bool comp(A aref, A bref)
{
return aref.a<bref.a;
}
if i put this function in a icomparable, implementation may become
complex,
built-in sort of List can't do this, can it ? How can I make a sort()
then ?
> Hi Deniel,
>
[quoted text clipped - 35 lines]
> >>
> >> > How can I resize a list ? thanks
Mark R. Dawson - 18 Nov 2006 06:59 GMT
Hi Deniel,
here is an example of how you can sort the contents of your list using an
anonymous delegate, which makes it very simple to sort the items in the list:
class Person
{
private string name;
public Person(string name)
{
this.name = name;
}
public string Name
{
get
{
return this.name;
}
}
}
static void Main(string[] args)
{
List<Person> people = new List<Person>();
Person mark = new Person("mark");
Person bob = new Person("bob");
Person frank = new Person("frank");
people.Add(mark);
people.Add(bob);
people.Add(frank);
people.Sort(delegate(Person p1, Person p2)
{
return p1.Name.CompareTo(p2.Name);
}
);
for (int i = 0; i < people.Count; ++i)
{
Console.Out.WriteLine(people[i].Name);
}
Console.ReadLine();
}
HTH
Mark.

Signature
http://www.markdawson.org
> Thanks Dave for your answer,
> I still wonder how i can sort the list based on the comparison of "a"
[quoted text clipped - 49 lines]
> > >>
> > >> > How can I resize a list ? thanks
Dave Sexton - 18 Nov 2006 07:03 GMT
Hi Deniel,
Try the following code:
List<int> list = new List<int>();
list.Add(10);
list.Add(3);
list.Add(16);
list.Sort(
delegate(int i1, int i2) // anonymous method
{
return i1.CompareTo(i2);
});

Signature
Dave Sexton
> Thanks Dave for your answer,
> I still wonder how i can sort the list based on the comparison of "a"
[quoted text clipped - 49 lines]
>> >>
>> >> > How can I resize a list ? thanks
Thanks Dave for your help
> Hi Deniel,
>
[quoted text clipped - 35 lines]
> >>
> >> > How can I resize a list ? thanks