我正在处理列表。我现在正在尝试确定 list first
:next
和last
. 我已经能够通过函数确定列表中项目的第一个和最后一个位置,getPostion
并通过标签显示项目名称。我的表单中的三个按钮: ShowFirstItem ShowNextItem 和 ShowLastItem 在标签中显示相应的项目。我在显示下一个项目时遇到问题。我有特殊的方法来next
调用GetNextTree
。当我从内部ShowNextItem
单击调用此方法时,我收到此错误:Cannot implicitly convert type 'TreeFarm.Form1.fruit_trees' to 'string'.
如何避免此错误并显示当前指向的项目?
namespace TreeFarm {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
public class ListForTrees {
public fruit_trees GetNextTree() {
//save currently pointed tree
fruit_trees tree = this.current_tree;
if (tree != null) {
//move current_tree to the next tree, to be returned next time
current_tree = current_tree.next_tree;
//return saved tree object
}
return tree;
}
}
private void ShowNextItem_Click(object sender, EventArgs e) {
//Show Next Item
labelSpecificTree.Text = mainlist.GetNextTree();
}
}