C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Retrieving data from ArrayList with Objects


Posted Date: 01 Oct 2007    Resource Type: Code Snippets    Category: C# Syntax

Posted By: Bindu Bujji       Member Level: Gold
Rating:     Points: 7



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);




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Using ArrayList  .  Retrieving Objects from ArrayList  .  Retrieving Data from ArrayList with Objects  .  Retrieving Data from ArrayList  .  Arraylist with Objects  .  ArrayList example  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Inserting data in grid
Previous Resource: Creating Log files
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it support

Contact Us    Privacy Policy    Terms Of Use