-
September 30th, 2011, 05:48 AM
#1
Sorting arrays (int)..
Hi!
Im new at csharp and right now im trying to sort my list.. I want the childs birth to be sorted. But it doesnt work
Can anybody help me?
My program:
class Barn1
{
static void Main()
{
Barn[] a = new Barn[5];
int quantityChild =0;
while (true)
{
Console.Write("Childs name? ");
string nn = Console.ReadLine();
if (nn == null)
break;
Console.Write("Childs birth? ");
int age = int.Parse(Console.ReadLine());
int i;
for (i = 0; i < quantityChild && string.Compare(nn, a[i].Namn, true) != 0; i++) ;
if (i == quantityChild) {
a[i] = new Barn(nn);
quantityChild++;
}
a[i].Ålder = age;
}
Console.WriteLine("Age".PadLeft(40));
Console.WriteLine("=====".PadLeft(40));
for (int j = 0; j < quantityChild; j++)
Console.WriteLine(a[j].Namn.PadRight(20) +
a[j].Ålder.ToString().PadLeft(18));
}
}
class Barn
{
string namn;
int ålder;
public Barn(string n)
{
namn = n;
}
public string Namn
{
get { return namn; }
}
public int Ålder
{
get { return ålder; }
set
{
ålder = value;
}
}
}
-
October 1st, 2011, 06:31 AM
#2
Re: Sorting arrays (int)..
Rigth now your are not doing any sorting at all. Do you want to sort the children at insertion or afterwords?
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
|