Sorting arrays (int)..
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Sorting arrays (int)..

  1. #1
    Join Date
    Sep 2011
    Posts
    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;

    }
    }

    }

  2. #2
    Join Date
    Oct 2011
    Posts
    6

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center