Enter a Number : 10 Value Type : Previous Value : 10 Current Value :10 Reference Type : Previous Value : 10 Current Value :11
Users Online
· Guests Online: 140
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
Value Type Parameter vs Reference Type Parameter in C#
Value Type Parameter vs Reference Type Parameter in C#
This C# Program Demonstrates the Difference between Value Type Parameter and Reference Type Parameter.The increment of an variable id done by both value type parameter and reference type parameter.
Here is source code of the C# Program to Demonstrate the Difference between Value Type Parameter and Reference Type Parameter. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
-
/*
-
* C# Program to Demonstrate the Difference between
-
* Value Type Parameter and Reference Type Parameter
-
*/
-
using System;
-
namespace Example1
-
{
-
class Program
-
{
-
public static void value(int num)
-
{
-
num++;
-
}
-
public static void reference(ref int num)
-
{
-
num++;
-
}
-
-
static void Main(string[] args)
-
{
-
int num;
-
Console.Write("Enter a Number:\t");
-
num = Convert.ToInt32(Console.ReadLine());
-
Console.WriteLine("\n\tValue Type:");
-
Console.Write("\nPrevious Value:\t{0}", num);
-
Program.value(num);
-
Console.Write("\nCurrent Value:\t{0}", num);
-
Console.WriteLine("\n\tReference Type");
-
Console.Write("\nPrevious Value:\t{0}", num);
-
Program.reference(ref num);
-
Console.Write("\nCurrent Value:\t{0}", num);
-
Console.ReadLine();
-
}
-
}
-
}
Here is the output of the C# Program:
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.