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 |
What is xpath in c#?
Why do we use lambda expression in c#?
Explain about Serialize and MarshalByRef?
What's c# ?
Why is xml called extensible?
What is a static field?
How do you generate documentation from the C# file commented properly with a command-line compiler?
What is the difference between firstordefault and singleordefault?
What is the meaning of extention?
Can you have parameters for static constructors?
Is functional interface runnable?
What is a constructor in c#?