C# 在表单之间传递二叉搜索树
我目前正在尝试访问我在form1中在form2中创建的二进制搜索树。第一张表格的代码是:C# 在表单之间传递二叉搜索树,c#,winforms,binary-search-tree,C#,Winforms,Binary Search Tree,我目前正在尝试访问我在form1中在form2中创建的二进制搜索树。第一张表格的代码是: public Home() { InitializeComponent(); } AddArtist secondForm = new AddArtist(); BSTree<Artist> ArtistCollection = new BSTree<Artist>(); private void btnAdd_Click(object sender, EventArgs
public Home() {
InitializeComponent();
}
AddArtist secondForm = new AddArtist();
BSTree<Artist> ArtistCollection = new BSTree<Artist>();
private void btnAdd_Click(object sender, EventArgs e) {
secondForm.ShowDialog();
}
我尝试过在自己的类中声明它的方法,所以没有结果 只需在您的第一个表单中将
ArtistCollection
作为属性公开即可
public BSTree<Artist> ArtistCollection { get; set; }
或者,在Form2中创建一个新的构造函数
public Form2(BSTree<Artist> artistCollection)
{
this.artistCollection = artistCollection;
}
public Form2(bTree Artist收藏)
{
this.artistCollection=artistCollection;
}
在实例化第二个表单时,他们必须首先传递“this”,然后在第二个表单的构造函数中处理它
var tree = form1.ArtistCollection;
public Form2(BSTree<Artist> artistCollection)
{
this.artistCollection = artistCollection;
}