Here is the small example for retrieving values from an ArrayList. In this sample, the ArrayList contains Object, and not primitive data types.
//First create any class
class Customer { private string custName; private decimal amount;
public Customer(string inName, decimal inAmount) { custName = inName; amount = inAmount; } public string Name { get {return custName; } }
public decimal Amount { get { return amount; } } }
The following code can be tried by wrapping it in a Main() method.
//NOW CREATE ARRAYLIST;
customer c1 = new customer("Ramya",12000); customer c2 = new customer("Sudha", 9000);
ArrayList myList = new ArrayList(); myList.add(c1); myList.add(c2);
// NOW RETRIEVE ARRAYLIST VALUES:
string msg=""; foreach(customer objC1 in myList) { msg += objC1.Name + " " + objC1.Amount ; }
MessageBox.show(msg);
|
No responses found. Be the first to respond and make money from revenue sharing program.
|