我有一种预感,我会收到很多“你这个 N000B”的评论。
我有这门课:
public partial class FindAndReplace : Form
{
public FindAndReplace()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
我希望能够做这样的事情来存储在其他函数中使用的引用:
public partial class FindAndReplace : Form
{
SomeRefType m_TabRef; // Dont know what type to use
public FindAndReplace(ref TabControl launguageTabs)
{
InitializeComponent();
m_TabRef = languageTab;
}
private void button1_Click(object sender, EventArgs e)
{
// use m_TabRef here that will change the original I passed in
}
}
一种解决方法是使用 TabControl 的副本并返回我想要标记的位置。我只是想知道我是否可以使用原件。
如果人们也用谷歌搜索这篇文章,我认为这篇文章可能会有用。
如果这是 C++,那就很容易了:/
最佳答案
由于 TabControl 已经是引用类型,您可以简单地使用它:
TabControl m_TabRef;
public FindAndReplace(TabControl launguageTabs)
{
m_TabRef = languageTab;
// from now m_TabRef references the object instance
// passed as launguageTabs reference
}
关于c# - 在 C# 中存储 ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8417649/