我该如何定义一个List作为结构体的字段?如何在asp c#中的struct中定义一个列表?
事情是这样的:
public struct MyStruct
{
public decimal SomeDecimalValue;
public int SomeIntValue;
public List<string> SomeStringList = new List<string> // <<I Mean this one?
}
,然后使用该字符串像这样:
Private void UseMyStruct()
{
MyStruct S= new MyStruct();
s.Add("first string");
s.Add("second string");
}
我已经尝试了一些东西,但他们都回传失误和不工作。
为什么
也就是说,你可以在(parameterfull)构造函数初始化它,像这样你不用''而不是'struct'吗? –
你总是可以使用's.SomeStringList.Add()'; – SWeko
好吧,我可以,但我不能定义列表结构.. 这是我的问题..不使用s.Add().. 请仔细阅读这篇文章。 如果您确定,请尝试下面的代码 – amin