居然自己被 值类型和引用类型 弄混了 哎

public class Temp
{
public string temp;
}
public struct cycle
{
public ServiceType servicetype;
public TimeEnum timeenum;
public DateTime time;
public TimeSpan sleeptime;
}

public void test(){

      List
<cycle> list1 = new List<cycle>();
cycle tt1
= new cycle();
tt1.servicetype
= ServiceType.Consult;
list1.Add(tt1);
cycle tt2
= list1[0];
tt2.servicetype
= ServiceType.CRM;
//List1[0] servicetype为Consult

List
<Temp> list = new List<Temp>();
Temp t1
= new Temp();
t1.temp
= "10";
list.Add(t1);
Temp t2
= list[0];
t2.temp
= "20";
//list[0] temp值为 20
}
记住一句话:struct text是一个结构。
List1[0]返回了结构的一个拷贝,在拷贝上赋值是没有意义的。

相关文章:

  • 2021-11-11
  • 2021-09-30
  • 2021-10-20
  • 2021-10-19
  • 2021-12-29
  • 2021-05-10
  • 2021-10-27
  • 2021-10-16
猜你喜欢
  • 2021-05-24
  • 2021-09-10
  • 2021-05-31
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案