嵌套列表未出现在智能感知中 visual studio
the nested list doesn't appear in intellisense visual studio
如您所见,我有这个模型:
public class UserNotes : BaseEntity
{
public IList<SymbolNotes> SymbolsNotes { get; set; }
public UserNotes(string userId): base($"UserNotes/{userId}")
{
}
}
public class SymbolNotes
{
public string Isin { get; set; }
public List<NoteItem> Notes { get; set; }
}
现在在我的代码中声明了一个名为 userNotes
的变量,
但是当我提出要点时,SymbolsNotes
不在列表中,为什么?
您有一个变量 userNotes
,其中包含 class UserNotes
的 IList
。为了简化,你可以想象你有一个盒子的集合,你在上面写了一个整数(盒子在集合中的索引),你拥有的每个盒子的内容是 UserNotes
class.
当你写userNotes.
时,你的目标是box的集合。因此,要访问 class UserNotes
的内容,您必须定位一个特定的框以查看其中的内容以访问该实例。然后只有您才能访问 属性 SymbolsNotes
.
另一种可视化方式就像一本纸质词典,它有很多翻译,但你不能只对编辑说“更改描述”,你必须说“更改第一个单词的描述”词典”,或“更改单词 'banana' 的描述”。
在 C# 中,您有多种可能性:
- Selecting by the index
- Selecting the first item with the
FirstOrDefault
Linq method
- Selecting one item that respects a condition with the
Single
Linq method
当然还有很多其他方法,但我只写了 3 种最常用的方法。
你可以这样:
使用索引
userNotes[0].SymbolsNotes.Add(newSymbolNotes);
使用 First
Linq 方法
userNotes.First().SymbolsNotes.Add(newSymbolNotes);
使用 Single
Linq 方法
userNotes.Single(/* Condition with lambda expression */).SymbolsNotes.Add(newSymbolNotes);
如您所见,我有这个模型:
public class UserNotes : BaseEntity
{
public IList<SymbolNotes> SymbolsNotes { get; set; }
public UserNotes(string userId): base($"UserNotes/{userId}")
{
}
}
public class SymbolNotes
{
public string Isin { get; set; }
public List<NoteItem> Notes { get; set; }
}
现在在我的代码中声明了一个名为 userNotes
的变量,
但是当我提出要点时,SymbolsNotes
不在列表中,为什么?
您有一个变量 userNotes
,其中包含 class UserNotes
的 IList
。为了简化,你可以想象你有一个盒子的集合,你在上面写了一个整数(盒子在集合中的索引),你拥有的每个盒子的内容是 UserNotes
class.
当你写userNotes.
时,你的目标是box的集合。因此,要访问 class UserNotes
的内容,您必须定位一个特定的框以查看其中的内容以访问该实例。然后只有您才能访问 属性 SymbolsNotes
.
另一种可视化方式就像一本纸质词典,它有很多翻译,但你不能只对编辑说“更改描述”,你必须说“更改第一个单词的描述”词典”,或“更改单词 'banana' 的描述”。
在 C# 中,您有多种可能性:
- Selecting by the index
- Selecting the first item with the
FirstOrDefault
Linq method - Selecting one item that respects a condition with the
Single
Linq method
当然还有很多其他方法,但我只写了 3 种最常用的方法。
你可以这样:
使用索引
userNotes[0].SymbolsNotes.Add(newSymbolNotes);
使用 First
Linq 方法
userNotes.First().SymbolsNotes.Add(newSymbolNotes);
使用 Single
Linq 方法
userNotes.Single(/* Condition with lambda expression */).SymbolsNotes.Add(newSymbolNotes);