【发布时间】:2017-11-18 21:12:44
【问题描述】:
在我的原始代码中,我有一个包含 2 列的列表对象,Word 和 Percent。我对列表进行了排序,但只想返回仅包含单词的列表
下面是一些简单的示例代码:
Public Function SortMyWords() as list(of string)
Dim Words As WordsToSort
Dim ListofWords As New List(Of WordsToSort)
Words.Word = "John"
Words.Percent = "10"
ListofWords.Add(Words)
Words.Word = "Robert"
Words.Percent = "1"
ListofWords.Add(Words)
ListofWords = ListofWords.OrderBy(Function(x) x.Percent).ToList()
End Sub
Public Structure WordsToSort
Public Word As String
Public Percent As String
Public Sub New(ByVal _word As String, ByVal _percent As String)
Word = _word
Percent = _percent
End Sub
End Structure
在SortMyWords 函数的末尾,我想将Word 列作为列表返回,我不确定我是否可以直接执行此操作 - 即
Return Listofwords(column Word) 或者我是否需要将我的 ListofWords 复制到一个新列表中,只包含列字 - 类似这样的东西(不起作用)
Dim Newlist As New List(Of String)
Newlist.AddRange(ListofWords(Words.Word))
Return NewList
任何关于我是否应该以完全不同的方式(更好)来做这件事的建议都会非常感激,因为我正试图让我的头脑围绕对象,虽然我一直在使用它们,但我对结构和列表对象还是陌生的。
感谢您的帮助,这已经让我发疯了一个小时。
【问题讨论】: