gpt4 book ai didi

c# - 使用初始化器访问对象的属性

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:19 28 4
gpt4 key购买 nike

我有这个代码:

public class TopTen
{
public int Id { get; set; }
public string ShortDesc { get; set; }
public string LongDesc { get; set; }
public Image Photo { get; set; }
}

public class Image
{
public string ImgUrl { get; set; }
public string AlterText { get; set; }
}

我可以这样做来赋值:

new topten()
{
/*
here I can access and give values to my properties. BUT i cant
access and give values to the properties in my `Image` class.
This is a problem because I would like to upload the new object as a json-file.
So how do I access the properties in `Image`?
*/
}

最佳答案

var x = new TopTen
{
Id = 1,
Photo = new Image
{
ImgUrl = "pic.jpg",
AlterText = "This is a picture"
}
};

关于c# - 使用初始化器访问对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23083051/

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