> ----- Original Message ----- > From: "Ankit Bhurat" <[EMAIL PROTECTED]> > a) One book said that all the objects of type Struct are of value type > and all Class Objects are of reference types . > The same book said : If cTest is a class then > > cTest x = new cTest(); > cTest y ; > > both x and y are variables of type reference.
This is true. > b) the other book said that all variables declared with "new" are > reference variable and are allocated memory on managed heap. And value type > are allocated memory on stack. This is not true. Even value types can be initialized with the new keyword. Unlike unmanaged C++ it is when the type is defined that you decide if it is a value type or a reference type. Actually if the class inherits from System.ValueType it is a value type, otherwise it is a reference type. It is not how the variables are declared and initialized by the user of a type that decides if the type is a value or reference type. This might feel a bit unintuitive at first :-) It is true that value types are allocated on the stack (unless they are boxed) and reference types are allocated on the managed heap, however. Check out the following article [1]. /Joakim http://www.jkarlsson.com [1] http://msdn.microsoft.com/library/default.asp?url=/msdnmag/issues/1200/dotnet/toc.asp =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com
