c#写一个计算器程序
using System;
namespace CalculatorApplication {
class NumberManipulator {
public void swap(ref int x, ref int y) {
int temp;
temp = x; /* 保存 x 的值 */
x = y; /* 把 y 赋值给 x */
y = temp; /* 把 temp 赋值给 y */
}
static void Main(string[] args) {
// 定义变量.
int a = 100;
int b = 200;
Console.WriteLine("在交换前 a 的值:{0}", a);
Console.WriteLine("在交换前 b 的值:{0}", b);
// 对象创建实例.
NumberManipulator n = new NumberManipulator();
// 调用函数来交换两个变量的值.
n.swap(ref a, ref b);
Console.WriteLine("在交换后 a 的值:{0}", a);
Console.WriteLine("在交换后 b 的值:{0}", b);
Console.ReadLine(); } }
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!