.NET Framework - Value Types vs Reference Types

 

 

  

Value Types

Reference Types

  A value type holds a data value within its own memory space Reference type stores the address of the Object where the value is being stored. It is a pointer to another memory location.
Example:
int a = 30;`
string b = "Hello Guru99!!";
Definition: A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.
Includes:
  • All numeric data types

  • Boolean , Char, and Date

  • All structures, even if their members are reference types

  • Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong

  • String

  • All arrays, even if their elements are value types

  • Class types, such as Form

  • Delegates

Holds Actual Data: Yes No
Pointer to another memory location: No Yes
Example: Char, Integer Class, Object, String
Memory Allocation: On stack or in-line in structure On heap

.NET Framework - Boxing and Unboxing

 

 

 

Now that we have seen difference between Value Types and Reference Types lets look at how can we convert value type to reference type and vice versa.

  Boxing Unboxing

Conversion of:

 Value type to Reference type.  Reference type to Value type.
Process of : Boxing is the process of converting a value type  to the type object or to any interface type implemented by this value type. Unboxing extracts the value type from the object.
How it works: Boxing a value type allocates an object instance on the heap and copies the value into the new object. For the unboxing of value type to succeed at run time, the item being unboxed must be a reference to an object that was previously created by boxing an instance of that value type.
Stores at: Reference type stored at managed (garbage-collected) heap. Value type stored at stack.
For Example:
int i = 123;
// The following line boxes i. 
object o = i; // implicit boxing
object ob = (object)i; // explicit boxing
int i = 123;   // a value type 
object o = i;   // boxing 
int j = (int)o;  // unboxing
Diagram:
https://i-msdn.sec.s-msft.com/dynimg/IC97798.gif

https://i-msdn.sec.s-msft.com/dynimg/IC135292.gif

.NET Framework Versions and Dependencies

Refrence - .NET Framework Versions and Dependencies

  • List the new features added in .NET Framework 4.0.
    • •Improved Application Compatibility and Deployment Support
    • •Dynamic Language Runtime
    • •Managed Extensibility Framework
    • •Parallel Programming framework
    • •Improved Security Model
    • •Networking Improvements
    • •Improved Core ASP.NET Services
    • •Improvements in WPF 4
    • •Improved Entity Framework (EF)
    • •Integration between WCF and WF  

What is a GAC?

  • Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache.

  • The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.​​

The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system. 

Starting with the .NET Framework 4, the default location for the global assembly cache is %windir%\Microsoft.NET\assembly.

In earlier versions of the .NET Framework, the default location is %windir%\assembly.


.NET Framework vs .NET Core

 

BASED ON

.NET CORE

.NET FRAMEWORK

Open Source .Net Core is an open source. Certain components of the .Net Framework are open source.
Cross-Platform Works on the principle of “build once, run anywhere”. It is compatible with various operating systems — Windows, Linux, and Mac OS as it is cross-platform. .NET Framework is compatible with the windows operating system. Although, it was developed to support software and applications on all operating systems.
Application Models .Net Core does not support desktop application development and it rather focuses on the web, windows mobile, and windows store. .Net Framework is used for the development of both desktop and web applications as well as it supports windows forms and WPF applications.
Installation .NET Core is packaged and installed independently of the underlying operating system as it is cross-platform. .NET Framework is installed as a single package for Windows operating system.
Support for Micro-Services and REST Services .Net Core supports the development and implementation of micro-services and the user has to create a REST API for its implementation. .Net Framework does not support the development and implementation of microservices but it supports the REST API services.
Performance and Scalability  .NET Core offers high performance and scalability. .Net Framework is less effective in comparison to .Net Core in terms of performance and scalability of applications.
Compatibility .NET Core is compatible with various operating systems — Windows, Linux, and Mac OS. .NET Framework is compatible only with the Windows operating system.
Android Development .NET Core is compatible with open-source mobile application platforms, i.e. Xamarin, through the .NET Standard Library. Developers use Xamarin’s tools to configure the mobile app for specific mobile devices such as iOS, Android, and Windows phones. .NET Framework does not support any framework for mobile application development.
Packaging and Shipping .Net Core is shipped as a collection of Nugget packages. All the libraries of .Net Framework are packaged and shipped together.
Deployment Model Whenever the updated version of .NET Core gets initiated; it is updated instantly on one machine at a time, thereby getting updated in new directories/folders in the existing application without affecting it. Thus, .NET Core has a good and flexible deployment model. In the case of .Net Framework, when the updated version is released it is first deployed on the Internet Information Server only.
CLI Tools .NET Core provides light-weight editors and command-line tools for all supported platforms. .Net Framework is heavy for Command Line Interface and developers prefer to work on the lightweight Command Line Interface.