Types in C# 

In Chapter 2Understanding Classes, Structures, and Interfaces, we learned that a variable can acquire the following types of values:

  • Value typesIn value types, the variables contain the actual value of the variable. This basically implies that if any change is made to a value type variable in a different scope of the program, the change is not reflected back once the control shifts to the calling function. 
  • Reference types: The data member contains the exact address of the variable in memory. As the variable just contains a reference to a memory address, two separate reference type variables can point to the same memory address. Therefore, if a change is made in a reference type variable, the change is made directly at the memory location of the variable and hence is carried forward to the different scopes present in the program execution. 
  • Pointer types: Pointers are another type of variable possible in C#. The pointer type is used to save the memory address of variable allowing us to any operation involving the memory location of the variable.

In the next section, we will do a deep dive into pointers and understand the implications and benefits of using them in our application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.21.47