ArrayList is reinitialising when a method is called

From a quick review of that block : while(a!=0){ … else if(a==2) {d=new User_Interface2(); d.showData();} else if(a==3) {d=new User_Interface2(); d.main();} } You are creating a new instance on each iteration. Create d outside the loop and reuse that instance. d=new User_Interface2(); while(a!=0){ … else if(a==2) { d.showData(); } else if(a==3) { d.main(); } }

Saving values from arraylist to txt C# [closed]

static void SaveArray() { ArrayList myArray = new ArrayList(); myArray.Add(“First”); myArray.Add(“Second”); myArray.Add(“Third”); myArray.Add(“and more”); StreamWriter sw= File.CreateText(@”C:\file.txt”); foreach (string item in myArray) { sw.WriteLine(item); } sw.Close(); } and you shouldn’t use arraylist not because its 2013 ,but because arraylist boxing each item in the array, where List store the type also. this cost less in … Read more