C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Value type/ref type


Posted Date: 06 Sep 2008      Total Responses: 3

Posted By: ezhilarasi       Member Level: Bronze     Points: 1



structure is a value type so it will be stored in stack. if structure contain ref type ie string which is a ref type where it will b stored.........




Responses

Author: Shanthi M    06 Sep 2008Member Level: GoldRating:     Points: 5

Structs are value types, while classes are reference types, and the runtime deals with the two in different ways.

When a value-type instance is created, a single space in memory is allocated to store the value. Primitive types such as int, float, bool and char are value types.

When the runtime deals with a value type, it is dealing directly with its underlying data and this can be very efficient, particularly with primitive types.



Author: Abhijeet Kumar    06 Sep 2008Member Level: GoldRating:     Points: 6

Value types directly contain there value on stack.
While reference types contain a value that is a pointer to the value on heap.

So being a value type Struct will be allocated on Stack and its size will be a sum of all the variables it has. So a store will also be allocated for string on stack and it will contain a reference to its value on Heap.

Basically for reference type in this case memory will be allocated both on Heap and Stack.

This is my understanding about the Value and reference types, If Somebody can refine my knowledge, it would be great.



Author: RishiRaj    08 Sep 2008Member Level: GoldRating:     Points: -20

In simple words, all value based types are allocated on the stack, while all reference based types are allocated on the heap. What does this mean? A value type contains the actual value. A reference type contains a reference to the value. When a value type is assigned to another value type, it is copied. When a reference type is assigned to another reference type, a reference is assigned to the value.

By saying stack, we mean things are kept one on top of the other. We keep track of each value at the top. By saying heap, we mean things are kept in a mashed order. We keep track of each value by its address, that is referenced by a pointer to it.

All value types are implicitly derived from System.ValueType. This class actually overrides the implementation in System.Object, the base class for all objects which is a reference type itself.

Data types like integers, floating point numbers, character data, Boolean values, Enumerations and Structures are examples of Value Types. Classes, Strings, Arrays are examples of Reference Types.

A value type may not contain NULL values. Reference types may contain NULL values.

It is not possible to derive new types from Value Types. This is possible in Reference types. However, Value Types like Structures can implement interfaces.




Post Reply
You must Sign In to post a response.
Next : retrival of date problme in vb.net - very urgent
Previous : .Net
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use