Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi In call by value and call by reference
how to effect values

C#
using system;
class sample
{
private int a,b,c;
public void getdata(int a,int b)
{
this.a=a;
this.b=b;
}
public void caldisp()
{
int c;
this.c=a+b;
c=this.c;
console.wriline(a+""+b+""+c+""+this.c);
}}
class program
{
p.s.v.m()
{
console.write("enter 1st value");
int i=int.parse(console.readline());
console.write("enter 2nd value");
int j=int.parse(console.readline());
sample s=new sample();
s.getdata(i,j);
s.caldisp();
}}
call by reference
<pre lang="cs">using system;
class sample
{
private int a,b;
public void show(int x,int y,out int s,out int p)
{
a=x;
b=y;
s=a+b;
p=a*b;
}}
class program
{
p.s.v.m()
{
int i=18;int j==29;
int r1,r2;
sample s=new sample();
s.show(i,j,out r1,out r2)
console.write("sum is="+r1);
console.write("sum is="+r2);
}}
Posted
Updated 6-Oct-15 9:44am
v3
Comments
Maciej Los 6-Oct-15 15:46pm    
What kind of method it is: "console.wriline"?

1 solution

Try this:
C#
using System;
public class Program
{
  static void by_value(int x)
  {
    x = 42;
  }

  static void by_reference(ref int x)
  {
    x = 42;
  }


  public static void Main()
  {
    int i = 0;
    by_value(i);
    Console.WriteLine("after by_value, i = {0}", i);
    by_reference(ref i);
    Console.WriteLine("after by_reference, i = {0}", i);
  }
}
 
Share this answer
 
Comments
suresh92 6-Oct-15 15:45pm    
oki want hard answer..
CPallini 6-Oct-15 15:46pm    
?
Maciej Los 6-Oct-15 15:48pm    
:laugh:
It couldn't be more hard...
Maciej Los 6-Oct-15 15:47pm    
The best explanation without any words.
5ed!
CPallini 6-Oct-15 15:49pm    
Thank you, Maciej!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900