日期:2014-05-17 浏览次数:20486 次
class Program
{
static void Main(string[] args)
{
List<string> names = new List<string>();
names.Add("Test");
Program p = new Program();
p.w(names);
p.AddItem(names);
p.w(names);
p.AddItem(ref names);
p.w(names);
Console.Read();
}
public void w(List<string> names)
{
foreach (string s in names)
{
Console.WriteLine(s);
}
Console.WriteLine();
}
public void AddItem(List<string> names)
{
names.Add("Test1");
}
public void AddItem(ref List<string> names)
{
names.Add("Test2");
}
}
public void AddItem(List<string> names)
{
names.Add("Test1");
names = new List<string>();//这个无效,不会改变names
}
public void AddItem(ref List<string> names)
{
names.Add("Test2");