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 a dll an assembly?

0 Answers  


Can we have 2 main methods in c#?

0 Answers  


Explain how do I convert a string to an int in c#?

0 Answers  


What is marshalling in c#?

0 Answers  


How can you sort the elements of the array in descending order?

4 Answers  






Difference between value and reference type. What are value types and reference types?

0 Answers  


What is ulong in c#?

0 Answers  


What is the use of command builder?

0 Answers  


What is continue in c#?

0 Answers  


1. What is IIS. pl explain practically. 2. Difference b/w webserver and application server. pl explain practically.

1 Answers  


t name of controls, which are displayed same in all browers?

1 Answers   TCS,


Why to use “using” in c#?

0 Answers  


Categories