gpt4 book ai didi

c# - 用一个参数解构不起作用

转载 作者:太空狗 更新时间:2023-10-30 00:23:02 24 4
gpt4 key购买 nike

<分区>

我有类 Person:

public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public void Deconstruct(out int id) { id = Id; }
}

当我尝试用以下代码解构它时:

var (id) = new Person();

编译器说:

Cannot infer the type of implicitly-typed deconstructor variable 'id'.

当有多个参数时,编译器不会说出来。像这样:

public void Deconstruct(out int id, out string name) { id = Id; name = Name; }

var (id, name) = new Person();

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com