Click here to Skip to main content
15,900,629 members
Home / Discussions / C#
   

C#

 
GeneralRe: Web Service Directory Pin
Guinness4Strength29-Jan-06 9:11
Guinness4Strength29-Jan-06 9:11 
GeneralRe: Web Service Directory Pin
Dave Kreskowiak29-Jan-06 12:35
mveDave Kreskowiak29-Jan-06 12:35 
Questionneed help with Windows Service Pin
hut22328-Jan-06 16:57
hut22328-Jan-06 16:57 
QuestionRemoting - Start / Stop Server Pin
Skoder28-Jan-06 16:26
Skoder28-Jan-06 16:26 
Question[Message Deleted] Pin
g00fyman28-Jan-06 16:00
g00fyman28-Jan-06 16:00 
QuestionCasting term vs Boxing/Unboxing - terminology question Pin
LuluSailor28-Jan-06 15:03
LuluSailor28-Jan-06 15:03 
AnswerRe: Casting term vs Boxing/Unboxing - terminology question Pin
Dave Kreskowiak28-Jan-06 18:57
mveDave Kreskowiak28-Jan-06 18:57 
GeneralRe: Casting term vs Boxing/Unboxing - terminology question Pin
LuluSailor29-Jan-06 7:35
LuluSailor29-Jan-06 7:35 
Regarding my terminology question... It seems like boxing is a specific way of casting (casting value type to reference type)? I just seem to find the two terms thrown around a lot and I want to make sure I am using them correctly.

I think I am getting the point of why I could not cast s2 = int(i2) ?? But to be sure, this is my take after reading responses: (Very simply put however!)....Basically string and int types are derived from the same parent class, so I cannot cast. Instead if I need to do the casting (correct term?), then I do this in C# by using the ToString method ( and in the background C# boxes the value (i.e. makes it an object )).

I hit the books and found various definitions for boxing/unboxing and only one definition for casting. But it never really helped me to know why I could not cast an int to a string. So thank-you for the help. It seems like some of the casting can be trial and error and the compiler in most cases will help you out; but if you care to look at the where the classes are coming from (the parent class) then you can figure out if the cast might work?


Various definitions of boxing (choose your favorite one Smile | :) )
1) Boxing: So that common operations can be performed on both reference types and value types, each value type has a corresponding hidden reference type. This is created when it is cast to a reference type. This process is called boxing.
2) Boxing: Value types are allocated on the stack by default, but they can always be converted into a heap-based reference-type object, called boxing.
3) Unboxing: The reverse of boxing is of course unboxing, which means that you can convert a heap-based reference-type object into its value-type equivalent…
4) Boxing and unboxing are the processes that enable value types (e.g., integers) to be treated as reference types (objects). The value is "boxed" inside an Object, and subsequently "unboxed" back to a value type.
5) Boxing At its simplest, boxing is the conversion of a value type to a reference type. The reciprocal case is when a reference type is unboxed back to a value type.
6) Boxing: Thus, a value type is “boxed” inside an object (when an object reference refers to a value type, a process know as boxing occurs).

Casting Definitions

Casting: Object of one type can be converted to objects of another type… It can be implicit or explicit.


-- modified at 13:43 Sunday 29th January, 2006
GeneralRe: Casting term vs Boxing/Unboxing - terminology question Pin
Dave Kreskowiak29-Jan-06 9:22
mveDave Kreskowiak29-Jan-06 9:22 
AnswerRe: Casting term vs Boxing/Unboxing - terminology question Pin
Guffa29-Jan-06 0:38
Guffa29-Jan-06 0:38 
QuestionParsing MS Word text Pin
emran83428-Jan-06 14:44
emran83428-Jan-06 14:44 
AnswerRe: Parsing MS Word text Pin
tarasn28-Jan-06 22:09
tarasn28-Jan-06 22:09 
GeneralRe: Parsing MS Word text Pin
emran83429-Jan-06 4:20
emran83429-Jan-06 4:20 
QuestionByte array + hex Pin
ita_cas28-Jan-06 8:25
ita_cas28-Jan-06 8:25 
QuestionUserControl Tutorial Pin
MarkMokris28-Jan-06 6:07
MarkMokris28-Jan-06 6:07 
AnswerRe: UserControl Tutorial Pin
Ravi Bhavnani28-Jan-06 16:54
professionalRavi Bhavnani28-Jan-06 16:54 
QuestionHow can I check if a mail exists or not? Pin
m.rastgar28-Jan-06 5:49
m.rastgar28-Jan-06 5:49 
AnswerRe: How can I check if a mail exists or not? Pin
Guffa28-Jan-06 12:02
Guffa28-Jan-06 12:02 
AnswerRe: How can I check if a mail exists or not? Pin
tarasn29-Jan-06 21:09
tarasn29-Jan-06 21:09 
AnswerRe: How can I check if a mail exists or not? Pin
Ista30-Jan-06 2:47
Ista30-Jan-06 2:47 
QuestionDefining nested namespace Pin
Ravi Bhavnani28-Jan-06 5:12
professionalRavi Bhavnani28-Jan-06 5:12 
AnswerRe: Defining nested namespace Pin
Guffa28-Jan-06 5:36
Guffa28-Jan-06 5:36 
GeneralRe: Defining nested namespace Pin
Ravi Bhavnani28-Jan-06 5:58
professionalRavi Bhavnani28-Jan-06 5:58 
Questionnewbie: do you ever define a class within a class ( Class A { Class B {} })? Pin
LuluSailor28-Jan-06 5:11
LuluSailor28-Jan-06 5:11 
AnswerRe: newbie: do you ever define a class within a class ( Class A { Class B {} })? Pin
Colin Angus Mackay28-Jan-06 5:48
Colin Angus Mackay28-Jan-06 5:48 

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.