我是C#的新手,我无法理解为什么这段代码不起作用。交换数组中2个元素的函数不起作用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char[] sw = "ab".ToCharArray();
swap(sw[0], sw[1]);
string end = new string(sw);
Console.Write(end);
}
static void swap(char a, char b)
{
char temp = a;
a = b;
b = temp;
}
}
}
我在控制台上的预期是“ba”,但我得到“ab”。我能够找到解决这个问题的不同方法,但我想知道的是这个代码中的错误。 感谢您的帮助!
感谢,认为C#做它总是由参,问题溶胶VED。 – user2373458 2013-05-11 18:24:58