【发布时间】:2015-03-23 18:54:12
【问题描述】:
为什么它会返回rainyday[1] = Sunday 而不是 Friday?和其他地方返回 main() 中定义的所有值
Namespace ConsoleApp_toTestYourself
{
public struct forecast
{
public int temp { get; set; }
public int press { get; set; }
}
class structStaticTest
{
public static void cts(string weather) { weather = "sunny"; }
public static void cta(string[] rainyDays) { rainyDays[1] = "Sunday"; }
public static void ctsr(forecast f) { f.temp = 35; }
static void Main(string[] args)
{
string weather = "rainy";
cts(weather); //calling static method
Console.WriteLine("the weather is " + weather);
string[] rainyDays=new[]{"monday","friday"};
cta(rainyDays); calling static method
Console.WriteLine("the rain days were on "+rainyDays[0]+" and "+ rainyDays[1]);
forecast f = new forecast { press = 700, temp = 20 };
ctsr(f); //calling static method
Console.WriteLine("the temperature is " + f.temp + "degree celcius");
Console.ReadLine();
}
}
}
它的输出是: 下雨 星期一星期天 20摄氏度
【问题讨论】:
-
你改变了rainyDays[1] = "Sunday"的值
标签: c# arrays value-type reference-type