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 are the types of assembly available

0 Answers  


What is c# console application?

0 Answers  


Distinguish between a class and struct?

0 Answers  


What is the use of generics in c#?

0 Answers  


What are the methods in c#?

0 Answers  


Could you explain the difference between func vs action vs predicate?

0 Answers  


What is the difference between struct and class in c#?

3 Answers  


write code for inserting and updating recoards in sql server database using connected architecture & records shoulds displayed in grid view ( use c# )

0 Answers  


How many bytes is a char c#?

0 Answers  


What is a datacontract?

0 Answers  


Can a class inherit structure.

4 Answers   IBM, Synechron,


Explain the ways to deploy an assembly?

0 Answers  


Categories