Click here to Skip to main content
16,013,944 members
Home / Discussions / C#
   

C#

 
Questionproblem converting to object Pin
humayunlalzad14-May-08 7:46
humayunlalzad14-May-08 7:46 
AnswerRe: problem converting to object Pin
Csharp™14-May-08 8:30
Csharp™14-May-08 8:30 
GeneralRe: problem converting to object Pin
Guffa14-May-08 9:35
Guffa14-May-08 9:35 
AnswerRe: problem converting to object Pin
Guffa14-May-08 9:40
Guffa14-May-08 9:40 
GeneralRe: problem converting to object Pin
humayunlalzad14-May-08 19:57
humayunlalzad14-May-08 19:57 
GeneralRe: problem converting to object Pin
Guffa15-May-08 0:55
Guffa15-May-08 0:55 
GeneralRe: problem converting to object Pin
humayunlalzad15-May-08 5:09
humayunlalzad15-May-08 5:09 
GeneralRe: problem converting to object Pin
Guffa15-May-08 6:53
Guffa15-May-08 6:53 
humayunlalzad wrote:
Yes but what I dont understand is, why is the object array, accepting string[] and not int[]. where as an object variable will accept a string or an int or anything.


When you store a string reference in an object reference variable, it's simply cast into an object reference. As the compiler knows that it's safe to store a string reference in an object reference variable, there is actually no conversion at all, the reference is just stored in the variable.

When you store an int value in an object reference variable, the value itself is not stored in the variable. Instead a new object is created on the heap, the int value is stored in this object, and the reference to the object is stored in the object reference variable. This is called boxing.

A string array can be handled as an object array, as they both contain references. An int array can not be handled as an object array, as it doesn't contain references. Instead each int in the array has to be boxed, and the references placed in an object array.

Boxing of single value types is done automatically, but there is no automatic boxing of all items in an array, as this could get very inefficient. Creating a value type array is efficient as it's still only one object, but if you could trigger an automatic boxing of all items in the array, you could accidentally create thousands of new objects.

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: problem converting to object Pin
humayunlalzad15-May-08 7:33
humayunlalzad15-May-08 7:33 
AnswerRe: problem converting to object [modified] Pin
The Nightcoder14-May-08 12:01
The Nightcoder14-May-08 12:01 
GeneralRe: problem converting to object Pin
humayunlalzad14-May-08 19:48
humayunlalzad14-May-08 19:48 
Questioninserting an image into a database Pin
Ofori Boadu14-May-08 7:22
Ofori Boadu14-May-08 7:22 
AnswerRe: inserting an image into a database Pin
Giorgi Dalakishvili14-May-08 7:42
mentorGiorgi Dalakishvili14-May-08 7:42 
Questiondsp problems Pin
t.wegrewicz14-May-08 6:52
t.wegrewicz14-May-08 6:52 
Questionerror saving arabic chars into my sql server 05 db Pin
Boshkash14-May-08 5:21
Boshkash14-May-08 5:21 
AnswerIGNORE Pin
leckey14-May-08 8:18
leckey14-May-08 8:18 
QuestionHow to create the Setup file in C# Console Application in .Net Pin
bruze14-May-08 4:24
bruze14-May-08 4:24 
AnswerRe: How to create the Setup file in C# Console Application in .Net Pin
led mike14-May-08 4:29
led mike14-May-08 4:29 
GeneralRe: How to create the Setup file in C# Console Application in .Net Pin
parth.p14-May-08 5:48
parth.p14-May-08 5:48 
GeneralRe: How to create the Setup file in C# Console Application in .Net Pin
bruze14-May-08 6:38
bruze14-May-08 6:38 
GeneralRe: How to create the Setup file in C# Console Application in .Net Pin
parth.p14-May-08 7:23
parth.p14-May-08 7:23 
GeneralRe: How to create the Setup file in C# Console Application in .Net Pin
bruze14-May-08 20:31
bruze14-May-08 20:31 
QuestionGlobal dictionary & partial class scheme - error: cannot be accessed with an instance reference Pin
RNEELY14-May-08 4:09
RNEELY14-May-08 4:09 
AnswerRe: Global dictionary & partial class scheme - error: cannot be accessed with an instance reference Pin
carbon_golem14-May-08 4:24
carbon_golem14-May-08 4:24 
QuestionAny bug in my Code? Pin
ASysSolvers14-May-08 3:27
ASysSolvers14-May-08 3:27 

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.