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 a dll an assembly?
Can we have 2 main methods in c#?
Explain how do I convert a string to an int in c#?
What is marshalling in c#?
How can you sort the elements of the array in descending order?
Difference between value and reference type. What are value types and reference types?
What is ulong in c#?
What is the use of command builder?
What is continue in c#?
1. What is IIS. pl explain practically. 2. Difference b/w webserver and application server. pl explain practically.
t name of controls, which are displayed same in all browers?
Why to use “using” in c#?