Click here to Skip to main content
15,845,279 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using underline in names Pin
Not Active6-Feb-08 15:41
mentorNot Active6-Feb-08 15:41 
GeneralRe: Using underline in names Pin
PIEBALDconsult6-Feb-08 14:11
mvePIEBALDconsult6-Feb-08 14:11 
GeneralRe: Using underline in names Pin
Kaveh Shahbazian7-Feb-08 0:16
Kaveh Shahbazian7-Feb-08 0:16 
GeneralReading Arabic text from text file Pin
Member 35841536-Feb-08 10:14
Member 35841536-Feb-08 10:14 
GeneralRe: Reading Arabic text from text file Pin
Not Active6-Feb-08 10:19
mentorNot Active6-Feb-08 10:19 
GeneralRe: Reading Arabic text from text file Pin
led mike6-Feb-08 10:21
led mike6-Feb-08 10:21 
GeneralRe: Reading Arabic text from text file Pin
Guffa6-Feb-08 14:55
Guffa6-Feb-08 14:55 
GeneralAccessing members of a class in an ArrayList Pin
hpjchobbes6-Feb-08 9:59
hpjchobbes6-Feb-08 9:59 
I am a beginner who is learning C# and have come across a problem that, while I have a workaround, would like to find out what I am doing wrong. I have tried searching, but I doubt I am using the correct terminology. Any assistance is very much appreciated!

If I create a class and place an object of that class into an ArrayList, is it possible to access the members of the object of a particular element of the ArrayList without having to first cast it to a new class?
<br />
public class Customer<br />
{<br />
  public Name;<br />
}<br />
<br />
ArrayList myArray = new ArrayList();<br />
Customer c = new Customer();<br />
<br />
ArrayList.Add(c);<br />
<br />
// Is there a way to do this?<br />
ArrayList[0].Name = "Bob Smith";<br />
<br />
// This is how I've done the workaround<br />
Customer temp = new Customer(); // Create a new customer temp object<br />
temp = ArrayList[0];  // Assign the customer from the array<br />
<br />
MessageBox.Show(temp.Name);<br />


My understanding of why the first way doesn't work is because an ArrayList could hold different object types. So I need to box/unbox it before I can use it. Is there some other way to go about doing what I am attempting here withouth the boxing/unboxing(I think these are the right terms)? If I am not using the terminology correctly, please let me know as that may be why my searches are comming up with very little information on what I am trying to do.

Thank you for your time and your patience with a beginner!
GeneralRe: Accessing members of a class in an ArrayList Pin
led mike6-Feb-08 10:15
led mike6-Feb-08 10:15 
GeneralRe: Accessing members of a class in an ArrayList Pin
Jimmanuel6-Feb-08 10:16
Jimmanuel6-Feb-08 10:16 
GeneralRe: Accessing members of a class in an ArrayList Pin
J$6-Feb-08 10:21
J$6-Feb-08 10:21 
AnswerRe: Accessing members of a class in an ArrayList Pin
Guffa6-Feb-08 10:22
Guffa6-Feb-08 10:22 
GeneralRe: Accessing members of a class in an ArrayList Pin
hpjchobbes6-Feb-08 10:41
hpjchobbes6-Feb-08 10:41 
GeneralRe: Accessing members of a class in an ArrayList Pin
User 66586-Feb-08 11:05
User 66586-Feb-08 11:05 
AnswerRe: Accessing members of a class in an ArrayList Pin
Guffa6-Feb-08 11:28
Guffa6-Feb-08 11:28 
GeneralMS SQL 2005 Pin
s3rro6-Feb-08 9:59
s3rro6-Feb-08 9:59 
GeneralRe: MS SQL 2005 Pin
J$6-Feb-08 10:13
J$6-Feb-08 10:13 
GeneralRe: MS SQL 2005 Pin
Not Active6-Feb-08 10:17
mentorNot Active6-Feb-08 10:17 
AnswerRe: MS SQL 2005 Pin
Nouman Bhatti6-Feb-08 22:54
Nouman Bhatti6-Feb-08 22:54 
GeneralBinding to DataTable built from mutliple database tables Pin
polishprogrammer6-Feb-08 9:54
polishprogrammer6-Feb-08 9:54 
GeneralRe: Binding to DataTable built from mutliple database tables Pin
Gareth H6-Feb-08 10:29
Gareth H6-Feb-08 10:29 
GeneralRe: Binding to DataTable built from mutliple database tables Pin
polishprogrammer6-Feb-08 10:49
polishprogrammer6-Feb-08 10:49 
GeneralRe: Binding to DataTable built from mutliple database tables Pin
Gareth H6-Feb-08 12:34
Gareth H6-Feb-08 12:34 
GeneralRe: Binding to DataTable built from mutliple database tables Pin
polishprogrammer6-Feb-08 19:08
polishprogrammer6-Feb-08 19:08 
News.NET Reference Code Downloader For Debugging With Visual Studio 2005 Pin
Izzet Kerem Kusmezer6-Feb-08 9:36
Izzet Kerem Kusmezer6-Feb-08 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.