请用C#编写程序:定义一个类,类中有方法能够完成两个数的互换,并编写完整程序。

比较急,请详细一些,谢谢了!

创建一个控制台项目,把代码全复制进去替换。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.AccessControl;

namespace ConsoleApplication1
{
    public static class C
    {
        public static void Change(ref int n1,ref int n2)
        {
            int num = n1;
            n1 = n2;
            n2 = num;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int a = 10, b = 20;
            C.Change(ref a,ref b);
            Console.WriteLine("调用Change函数后,a值为:{0}。b值为{1}", a, b);
            Console.Read();
        }
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-09
  using System;
  using System.Collections.Generic;
  using System.Text;

  namespace ChangeData
  {
  class Program
  {
  static void Main(string[] args)
  {
  Console.WriteLine("请输入第一个数");
  int a = Convert.ToInt32(Console.ReadLine());
  Console.WriteLine("请输入第二个数");
  int b = Convert.ToInt32(Console.ReadLine());
  Console.WriteLine("您输入的a={0},b={1}",a,b);
  switchData(ref a,ref b);
  Console.WriteLine("转换后a={0},b={1}", a, b);
  Console.WriteLine("输入任何字符退出");
  Console.ReadKey();
  }
  static void switchData(ref int a, ref int b)
  {
  int temp;
  temp = a;
  a = b;
  b = temp;
  }
  }
  }
第2个回答  2015-06-09
问题不是很清楚,就是简单的交换?
相似回答