c# - Define and set an array property with a single element -
this question has answer here:
i have class follows, api must in format
public class command { public string response_type { get; set; } public string text { get; set; } public attachment[] attachments { get; set; } = new attachment[] { new attachment { } }; } public class attachment { public string title { get; set; } public string title_link { get; set; } public string image_url { get; set; } }
so response_type, text , array of attachments. can see create attachment array , create empty object.
when creating object there ever 1 element in array.
how set or add array when declaring object, given object created in constructor
command result = new command() { text = "rebooting!", attachments[0] = ???? };
im missing simple, tried lots of combos
to add array need after construction
command result = new command() { text = "rebooting!", }; result.attachments = new attachment[2] { result.attachments[0], new attachment() };
if want set value (since array created , contains 1 instance can
result.attachments[0] = new attachment();
Comments
Post a Comment