Click here to Skip to main content
15,898,036 members
Home / Discussions / C#
   

C#

 
GeneralRe: C#.NET write to registry at installation time Pin
Thomas Stockwell8-Feb-08 7:34
professionalThomas Stockwell8-Feb-08 7:34 
GeneralI need help with a progra. Pin
Alex5016-Feb-08 16:52
Alex5016-Feb-08 16:52 
GeneralRe: I need help with a progra. Pin
Mark Churchill6-Feb-08 17:35
Mark Churchill6-Feb-08 17:35 
GeneralRe: I need help with a progra. Pin
N a v a n e e t h6-Feb-08 19:12
N a v a n e e t h6-Feb-08 19:12 
GeneralRe: I need help with a progra. Pin
Mark Churchill6-Feb-08 21:55
Mark Churchill6-Feb-08 21:55 
QuestionRaise VB6 event from C# dll [modified] Pin
MayyMagdy6-Feb-08 11:37
MayyMagdy6-Feb-08 11:37 
QuestionUsing underline in names Pin
Kaveh Shahbazian6-Feb-08 9:56
Kaveh Shahbazian6-Feb-08 9:56 
GeneralRe: Using underline in names Pin
Ed.Poore6-Feb-08 10:32
Ed.Poore6-Feb-08 10:32 
GeneralRe: Using underline in names Pin
Gareth H6-Feb-08 11:38
Gareth H6-Feb-08 11:38 
GeneralRe: Using underline in names Pin
Not Active6-Feb-08 14:41
mentorNot Active6-Feb-08 14:41 
GeneralRe: Using underline in names Pin
PIEBALDconsult6-Feb-08 13:11
mvePIEBALDconsult6-Feb-08 13:11 
GeneralRe: Using underline in names Pin
Kaveh Shahbazian6-Feb-08 23:16
Kaveh Shahbazian6-Feb-08 23:16 
GeneralReading Arabic text from text file Pin
Member 35841536-Feb-08 9:14
Member 35841536-Feb-08 9:14 
GeneralRe: Reading Arabic text from text file Pin
Not Active6-Feb-08 9:19
mentorNot Active6-Feb-08 9:19 
GeneralRe: Reading Arabic text from text file Pin
led mike6-Feb-08 9:21
led mike6-Feb-08 9:21 
GeneralRe: Reading Arabic text from text file Pin
Guffa6-Feb-08 13:55
Guffa6-Feb-08 13:55 
GeneralAccessing members of a class in an ArrayList Pin
hpjchobbes6-Feb-08 8:59
hpjchobbes6-Feb-08 8:59 
GeneralRe: Accessing members of a class in an ArrayList Pin
led mike6-Feb-08 9:15
led mike6-Feb-08 9:15 
GeneralRe: Accessing members of a class in an ArrayList Pin
Jimmanuel6-Feb-08 9:16
Jimmanuel6-Feb-08 9:16 
GeneralRe: Accessing members of a class in an ArrayList Pin
J$6-Feb-08 9:21
J$6-Feb-08 9:21 
AnswerRe: Accessing members of a class in an ArrayList Pin
Guffa6-Feb-08 9:22
Guffa6-Feb-08 9:22 
hpjchobbes wrote:
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?


You don't cast the object to a new class, you cast the reference of the object to the class. Creating a new class instance serves no purpose at all, that instance would be thrown away when you assign the new reference to the variable.

Customer temp; // Declare a reference<br />
temp = (Customer)ArrayList[0]; // Cast the object from the list


hpjchobbes wrote:
So I need to box/unbox it before I can use it.


Actually, boxing is only used for value types. If you for example store integers in an ArrayList, each integer is boxed inside an object which is stored on the heap. That way the integer becomes a reference type so that the reference can be stored in the ArrayList.

If you are using framework 2, you can use a generic list instead. They are type safe, so there is no need for any casting:

List<Customer> list = new List<Customer>();<br />
list.Add(new Customer());<br />
<br />
list[0].Name = "Eric Gently";<br />
<br />
Customer temp = list[0];


Generic lists also works with value types, so there is no boxing if you store value types in a list.

Experience is the sum of all the mistakes you have done.

GeneralRe: Accessing members of a class in an ArrayList Pin
hpjchobbes6-Feb-08 9:41
hpjchobbes6-Feb-08 9:41 
GeneralRe: Accessing members of a class in an ArrayList Pin
User 66586-Feb-08 10:05
User 66586-Feb-08 10:05 
AnswerRe: Accessing members of a class in an ArrayList Pin
Guffa6-Feb-08 10:28
Guffa6-Feb-08 10:28 
GeneralMS SQL 2005 Pin
s3rro6-Feb-08 8:59
s3rro6-Feb-08 8:59 

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.