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

Is c# and c same?

0 Answers  


Explain attributes in c#?

0 Answers  


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

0 Answers  


What is the difference between method parameters and method arguments. Give an example?

0 Answers  


What is tryparse c#?

0 Answers  






Can a static class have a constructor c#?

0 Answers  


Can we inherit static class in c#?

0 Answers  


An Array is a Ref Type? what about the array elements which are value type(int,Float...etc)?

6 Answers  


What is the use of main method in c#?

0 Answers  


What is the difference between constants and read-only?

0 Answers  


What is data adapter in c#?

0 Answers  


Why we use extension methods in c#?

0 Answers  


Categories