Value Type Parameter In C#

In this article i am explaining about parameter in C#. As mentioned previous chapter, there are two types of parameter that can be use in function. First  is Value type parameter and second is reference type parameter. Before understanding both type of parameter in C#, you will have to understand Value type and Reference type.

In two ways to allocating space in memory. First is value type and second is Reference type. When you create int, char or float type variable, it creates value type memory allocation whereas when you create object of class, it creates reference type memory allocation.

Value Type: A value type variable directly contains data in the memory.

Reference Type: A Reference type variable contains memory address of value.

Consider the following graph to make better sense of value type and reference type.

int Result;

In the preceding example, the value type variable contains the value whereas a reference type variable contains the address of Result variable.

Value Type Parameter:

In value type parameter, the actual value gets passed to the function. Passing a value type variable as parameter means, you are passing the copy of the value.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Value_Type_Example
    class Program
        public static int Qube(int num)
            return num * num * num;
        static void Main(string[] args)
            int val, number;
            number = 5;
            //Passing the copy value of number variable
            val = Program.qube(number);

Leave a Reply

Your email address will not be published. Required fields are marked *