90 318
Assignments Done
99.3%
Successfully Done
In September 2020

# Answer to Question #52289 in C# for Prashant Magar

Question #52289
Kathy, a software developer in FIT technologies, is assigned the task of optimizing the following
code:
using System;
public class SwapNumber
{
void SwapNum(ref int a, ref int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
static void Main(string[] args)
{
SwapNumber classobj = new SwapNumber();
int Number1, Number2;
Console.WriteLine(&quot;Enter the first number&quot;);
Console.WriteLine(&quot;Enter the second number&quot;);
Console.WriteLine(&quot;The value of first number is {0}&quot;,
Number1);
Console.WriteLine(&quot;The value of second number is {0}&quot;,
Number2);
classobj.SwapNum(ref Number1,ref Number2);
Console.WriteLine(&quot;Now the value of first number after
swaping is {0}&quot;, Number1);
Console.WriteLine(&quot;Now the value of second number after
swapping is {0}&quot;, Number2);
}
}
Optimize the preceding code for Kathy and find out the errors (if any). What would be the output of
the preceding code, if the first number is 46 while the second number is 37?
1
2015-06-04T03:36:49-0400
using System;
class Program {

static void Swap(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}

static void Main(string[] args)
{
int number1, number2;

Console.WriteLine("Enter the first number");
Console.WriteLine("Enter the second number");
Console.WriteLine("The value of first number is {0}", number1);
Console.WriteLine("The value of second number is {0}", number2);

Swap(ref number1,ref number2);
Console.WriteLine("Now the value of first number after swaping is {0}", number1);
Console.WriteLine("Now the value of second number afterswapping is {0}", number2);
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!