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



class Program { void add() { int x=10, y=20; ..

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

class Program { void add() { int x=10, y=20; ..

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

class Program { void add() { int x=10, y=20; ..

Answer / nvk

The Variable Sum Is Not defined

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Sharp Interview Questions

What is xpath in c#?

0 Answers  


Why do we use lambda expression in c#?

0 Answers  


Explain about Serialize and MarshalByRef?

0 Answers  


What's c# ?

0 Answers  


Why is xml called extensible?

0 Answers  


What is a static field?

0 Answers  


How do you generate documentation from the C# file commented properly with a command-line compiler?

2 Answers  


What is the difference between firstordefault and singleordefault?

0 Answers  


What is the meaning of extention?

0 Answers  


Can you have parameters for static constructors?

0 Answers  


Is functional interface runnable?

0 Answers  


What is a constructor in c#?

3 Answers  


Categories