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:
Enter a Number : 10 Value Type : Previous Value : 10 Current Value :10 Reference Type : Previous Value : 10 Current Value :11
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C# Programming examples, go to 1000 C# Programs.
Next Steps:
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice MCA MCQs
- Apply for Computer Science Internship
- Buy C# Books
- Practice Computer Science MCQs
- Apply for C# Internship