-
September 9th, 2009, 05:12 PM
#1
Sort Array of objects using custom class.
Hi there,
below is my question and the code I have so far, do I just need to fill in the CompareTo method with custome sort and if so do you know thw code?
Question:
Create a custom class that implements the necessary interfaces to allow an array of objects of that class to be sorted.
Answer so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Interfaces
{
class Program
{
static void Main(string[] args)
{
ArrayList array = new ArrayList(4);
for (int i = 60; i > 1; i -= 10)
{
aObj item = new aObj(i);
array.Add(item);
}
// foreach (Object o in array)
// Console.WriteLine(o);
array.Sort();
Console.ReadKey();
}
}
class aObj : IComparable
{
public object t;
public aObj (object _t)
{
t = _t;
}
#region IComparable Members
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
#endregion
public override string ToString()
{
return t.ToString();
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|