【发布时间】:2013-05-11 18:16:51
【问题描述】:
我是 C# 新手,我不明白为什么这段代码不起作用。
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”。我能够找到不同的方法来解决这个问题,但我想知道这段代码中的错误是什么。 感谢您的帮助!
【问题讨论】: