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
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 |
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 |
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??
Are c# objects passed by reference?
What are nullable types? Is Nullable<int> I and int ?i are same.
What is JIT (just in time)? how it works?
Is null or empty in c#?
What is the use of oops in c#?
Hi, Can we implement the Abstract class on interface in c#, If yes then provide the code implementation
What are the value types in c#?
What are data types examples?
coding for delegates?
What are the different states of a thread?
How many types of serialization are there in c#?