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

namespace Ascending_and_Descending_ex_2
{
    class employee
    {
        public float exp;
        public string ename;
        public string designation;
        public float sal;

        public employee(float e,string n,string d,float s)
    {
        exp = e;
        ename = n;
        designation = d;
        sal = s;

        Console.Write("{0} {1} {2} {3} ", exp, ename, designation, sal);
        Console.WriteLine("\n\n");
    }



    }
    class Program
    {
        static void Main(string[] args)
        {

            employee[] jigu = new employee[5];
            jigu[0] = new employee(3, "IZAT Ka Faluda", "Programmer", 40000);
            jigu[1] = new employee(5, "Temp puri", "Developer", 21368);
            jigu[2] = new employee(1, "Radhe Govind", ".net DBA", 32000);
            jigu[3] = new employee(7, "Only Jigi", "Oracle DBA", 32000);
            jigu[4] = new employee(2, "just 4 Jigs", "Oracle DBA", 38000);

            //int temp0 = 0;
            //int temp1 = 0;
            //int temp2 = 0;

            //Console.Write("Given List: ");
            //for (int i = 0; i < 5; i++)
            //{
            //    Console.Write(jigu[i]);
            //}

            //Console.WriteLine("\n");

            Console.WriteLine("enter your choice");
            int n = Int32.Parse(Console.ReadLine());


            if (n == 1)
            {
                for (int j = 0; j < jigu.Length; j++)
                {
                    for (int i = 0; i < jigu.Length; i++)
                    {
                        if (i != (jigu.Length - 1))
                        {
                            if (jigu[i].ename.CompareTo(jigu[i + 1].ename)>0)
                            {
                                string temp0 = jigu[i].ename;
                                float temp1  = jigu[i].exp;
                                string temp2 = jigu[i].designation;

                                jigu[i].exp = jigu[i + 1].exp;
                                jigu[i].ename = jigu[i + 1].ename;
                                jigu[i].designation = jigu[i + 1].designation;

                                jigu[i + 1].exp = temp1;
                                jigu[i + 1].ename = temp0;
                                jigu[i + 1].designation = temp2;
                            }
                        }
                    }
                }
            }
            else if (n == 2)
            {
                for (int j = 0; j < jigu.Length; j++)
                {
                    for (int i = 0; i < jigu.Length; i++)
                    {
                        if (i != (jigu.Length - 1))
                        {
                            if (jigu[i].exp < jigu[i + 1].exp)
                            {
                                float temp0 = jigu[i].exp;
                                string temp1 = jigu[i].ename;
                                string temp2 = jigu[i].designation;

                                jigu[i].exp = jigu[i + 1].exp;
                                jigu[i].ename = jigu[i + 1].ename;
                                jigu[i].designation = jigu[i + 1].designation;

                                jigu[i + 1].exp = temp0;
                                jigu[i + 1].ename = temp1;
                                jigu[i + 1].designation = temp2;
                            }
                        }
                    }
                }
            }
            else if (n == 3)
            {
                for (int j = 0; j < jigu.Length; j++)
                {
                    for (int i = 0; i < jigu.Length; i++)
                    {
                        if (i != (jigu.Length - 1))
                        {
                            if (jigu[i].sal < jigu[i + 1].sal)
                            {
                                float temp0 = jigu[i].sal;
                                string temp1 = jigu[i].ename;
                               string temp2 = jigu[i].designation;

                                jigu[i].sal = jigu[i + 1].sal;
                                jigu[i].ename = jigu[i + 1].ename;
                                jigu[i].designation = jigu[i + 1].designation;

                                jigu[i + 1].sal = temp0;
                                jigu[i + 1].ename = temp1;
                                jigu[i + 1].designation = temp2;
                            }
                        }
                    }
                }
            }
            Console.Write("Asecending order: ");
            for (int i = 0; i < jigu.Length; i++)
            {
                Console.WriteLine("\n");
                Console.WriteLine("{0} {1} {2} {3}", jigu[i].exp, jigu[i].ename, jigu[i].designation,jigu[i].sal);
            }
            Console.WriteLine("");

            Console.Write("Descending order: ");
            for (int j = jigu.Length; j > 0; j--)
            {
                Console.WriteLine("{0} {1} {2} {3}", jigu[j - 1].exp, jigu[j - 1].ename, jigu[j - 1].designation, jigu[j-1].sal);
            }
            Console.ReadLine();
        }
    }
}

Was there a question or you just showing us your code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.