Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
 public partial class Form1 : Form
    {
        Array Arraylist();//Error	4	' declare a body because it is not marked abstract, extern, or partial	

    int i = 0;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
       //	items.Sort(); 
	 ItemList.Sort();
     ItemList.Add("item1");
     ItemList.Add("Item2");
     ItemList.Add("Item3");
     ItemList.Add("Item4");
     ItemList.Add("Item5");
     for (i = 0; i < (ItemList.Count - 1); i++) ;
            lilsorted= ItemList.Sort();
            //items.reverse
     ItemList.Reverse();
     ItemList.Add("item1");
     ItemList.Add("Item2");
     ItemList.Add("Item3");
     ItemList.Add("Item4");
     ItemList.Add("Item5");
            foreach (ItemList.Reverse <  lilreverse.Text>));//Error	1	Idreversexpected	

             lilreverse = ItemList.Reverse();
        }
   
        private void button2_Click(object sender, EventArgs e)
        {
            item1.Text = ("");
   Item3    item2.Text = ("");
  Item4     item3.Text = ("");
 Item5      item4.Text = ("");
            item5.Text = ("");
   reverseilsorted.Text = ("");
            lilreversebutton ("");
        }
 

        private void button3_Click(object sender, EventArgs e)
      Arraylist       this.Close();
        }
    
public  ArrayList ItemList { get; set; }}


}
Posted
Updated 30-Mar-12 16:14pm
v3
Comments
Abhinav S 30-Mar-12 2:22am    
Code tags corrected.

I did not got what exactly you are asking for, can you explain more abt it.

If you want to sort and reverse arraylist, you can use method Sort() and Reverse().
Check this link[^]
 
Share this answer
 
I think generic list is easy to use for this purpose as shown below

C#
void Main()
{
	Form form1 = new Form();
	ListBox listBox1 = new ListBox();
	listBox1.Dock= DockStyle.Fill;
	form1.Controls.Add(listBox1);
	
	List<string> items = new List<string>{"Item5","Item2","Item4","Item1","Item3"};
	//Option1
	items.Sort((s1,s2)=>s2.CompareTo(s1));
	//Option2
//	items.Sort();
//	items.Reverse();
	
	listBox1.DataSource=items;
	form1.ShowDialog();
	
}
 
Share this answer
 
v3
First of all I would use the generic List<string> instead of non-generic Array. Unless you are going to be using the list for something besides string, you will speed things up by using generic and gives you more flexibility. Sorting can then be done with the List sort capability:

Array.Sort(delegate(string s1, string s2) 
    { 
      return s2.CompareTo(s1); 
    });


Solution 2 is correct in that you can do a Sort and Reverse, but that is an ArrayList or List<t></t> class, and you would be limited to the standard sort \. There is a Array.Reverse (ArrayList) that you can use (the sort is also a static method).
 
Share this answer
 
Try a countdown loop
C#
for (i = 4; i =0; i--)
{
}
 
Share this answer
 
C#

well all i try a differnt way seems like it was gna work but got stop error hear code any help i would be greatful

public partial class form1 : Form
{
public string[] StringArray { get; set; }
protected int counter = 0;
public form1()
{
InitializeComponent();
}


private void form1_Load(object sender, EventArgs e)
{
//seting array
TextBox item1 = sender as TextBox;
string str = item1.Text;
if (item1.Text != "")
item1.Enabled = false;
StringArray[counter] = item1.Text;
counter++;
TextBox item2 = sender as TextBox;

if (item2.Text != "")
item2.Enabled = false;
StringArray[counter] = item2.Text;
counter++;


TextBox item3 = sender as TextBox;

if (item3.Text != "")
item3.Enabled = false;
StringArray[counter] = item3.Text;
counter++;

TextBox item4 = sender as TextBox;

if (item4.Text != "")
item4.Enabled = false;
StringArray[counter] = item4.Text;
counter++;

TextBox item5 = sender as TextBox;

if (item5.Text != "")
item5.Enabled = false;
StringArray[counter] = item5.Text;
counter++;


}



private void displaybtn_Click(object sender, EventArgs e)
{

//sort of list
StringBuilder StrArrsort = new StringBuilder();
StringBuilder StrArrRev = new StringBuilder();

foreach (string str in StringArray) /// stop error {"Object reference not set to an instance of an object."}
{
StrArrsort.Append(str);
}
//rev of list
for (int i = StringArray.Length - 1; i >= 0; i--)
{
StrArrRev.Append(StringArray[i]);
}
// show list in lables
lilsorted.Text = StrArrsort.ToString();
lilrevers.Text = StrArrRev.ToString();
}

private void clearbtn_Click(object sender, EventArgs e)
{
item1.Text = ("");
item2.Text = ("");
item3.Text = ("");
item4.Text = ("");
item5.Text = ("");
lilsorted.Text = ("");
lilrevers.Text = ("");
}

private void exitbtn_Click(object sender, EventArgs e)
{
this.Close();
}



}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900