Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2010, 10:18 AM
Registered User
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default A litttle confused about structs and reference types

In the book it says "everything is an object" .

In chapter 9 it says "structs are value types" , "classes are reference types"

then it says "objects are reference types"

so are structs not objects?
 
Old October 1st, 2010, 08:35 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

All the statements are true, but I agree confusing :-)
Structs are objects when they are used as an object. This is known "boxing". If a struct is used as an object, it is boxed.
One small example:
int is a struct and thus a value type. Declaring and instantiating an int:
Code:
int x = 3;
Now assigning the int to an object, boxing happens:
Code:
object o = x;
Boxing also happens if an int is passed to a method that accepts an object parameter.
Page 303-305 gives more information on boxing.

Hope this helps.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Enums VS Structs MoDulus Intro Programming 4 January 19th, 2012 10:42 AM
Structs Will BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 4 January 12th, 2010 03:12 PM
as,in and reference types error msg..... raykaash C# 2005 2 January 8th, 2008 07:14 AM
arrays of structs seymour_glass C# 2 April 2nd, 2007 08:14 PM
Passing Reference Types by Value semiloof VS.NET 2002/2003 1 December 22nd, 2003 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.