110,535
社区成员
发帖
与我相关
我的任务
分享
//值类型的
class Program{
static void swap(int x, int y) {
int temp;
temp = x;
x = y;
y = temp;
}
public static void main(string[] args) {
int x =1;int y =2;
Program.void(x,y);
Console.Write("{0},{1}",x,y);
//我明白这个为什么x,y的值没有改变
}
}
static void Change(int[] array)
{
array[0] = 123;
}
static void Main()
{
int[] arr = {4,5,6};
Change(arr);
Console.WriteLine("{0}",arr[0]);
//这里是不是arr[0]会变成123呢?如果会(我认为会变),为什么string的就不行?string不是引用类型?
}
class A
{
public int X {get; set;}
public int Y {get; set;}
}
class B
{
public B(int x, int y){this.X = x; this.Y = y;}
public int X {get; private set;}
public int Y {get; private set;}
}
class Program{
static void swap(string x, string y) {
string temp;
temp = x;
x = y;
y = temp;
}
public static void main(string[] args) {
string x ="1";string y ="2";
Program.void(x,y);
Console.Write("{0},{1}",x,y);
//x,y的值没有改变,就是这个地方不清楚
}
}
class Program{
static void swap(string x, string y) {
string temp;
temp = x;
x = y;
y = temp;
}
public static void main(string[] args) {
string x ="1";string y ="2";
Program.void(x,y);
Console.Write("{0},{1}",x,y);
//x,y的值没有改变,就是这个地方不清楚
}
}