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

I wish to create a windows application to perform a similar function as that of the "Search" which is provided to look for related files and folders in the System.. What steps must i follow??

0 Answers  


Are c# objects passed by reference?

0 Answers  


What are nullable types? Is Nullable<int> I and int ?i are same.

2 Answers   TCS,


What is JIT (just in time)? how it works?

0 Answers  


Is null or empty in c#?

0 Answers  






What is the use of oops in c#?

0 Answers  


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

1 Answers   RHR, Wipro,


What are the value types in c#?

0 Answers  


What are data types examples?

0 Answers  


coding for delegates?

3 Answers   Tech Mahindra,


What are the different states of a thread?

0 Answers  


How many types of serialization are there in c#?

0 Answers  


Categories