class Program
{
void add()
{
int x=10, y=20;
fun();
Console.WriteLine("{0}", sum);
}
void fun()
{
int sum;
sum = x + y;
}
static void Main(string[] args)
{
Program f =new Program();
f.add();
}
}
Debug above program.....
Answers were Sorted based on User's Feedback
Answer / anandraj
class Program
{
void add()
{
int x = 10, y = 20,sum;
fun(x,y,out sum);//changing the parameters
Console.WriteLine("{0}", sum);
}
void fun(int x,int y,out int sum)//changing the
parameter and using out keyword
{
sum = x + y;
}
static void Main(string[] args)
{
Program f = new Program();
f.add();
}
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / simhachalam
Actually you defined x,y variable in add() function so that
variables you can't access outside of method .finally u got
error is undefined variables x,y.
Is This Answer Correct ? | 2 Yes | 1 No |
Is c# and c same?
Explain attributes in c#?
What operators can be used to cast from one reference type to another without the risk of throwing an exception?
What is the difference between method parameters and method arguments. Give an example?
What is tryparse c#?
Can a static class have a constructor c#?
Can we inherit static class in c#?
An Array is a Ref Type? what about the array elements which are value type(int,Float...etc)?
What is the use of main method in c#?
What is the difference between constants and read-only?
What is data adapter in c#?
Why we use extension methods in c#?