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 a pre-requisite for connection pooling?

1 Answers  


When static constructor is invoked?

9 Answers   TCS,


Can I use ReaderWriterLock instead of Monitor.Enter/Exit for Threading?

1 Answers   HCL,


What is a byte in c#?

1 Answers  


How to declares a two-dimensional array in C#?

1 Answers   DELL,


Explain About remoting and web services. Difference between them

1 Answers   Microsoft,


What is boolean method?

1 Answers  


How can you overload a method?

3 Answers  


Why do we need delegates?

1 Answers  


Can a private virtual method can be overridden?

1 Answers  


How many root nodes are there in an xml document?

1 Answers  


Hi, Can we implement the Abstract class on interface in c#, If yes then provide the code implementation

1 Answers   RHR, Wipro,


Categories