[英]Error: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
Today I started working with classes. 今天,我开始上课。 I created some classes to get my MainWindow.xmal.cs
a bit smaller. 我创建了一些类来使MainWindow.xmal.cs
变小。 After creating the first classes and debugging, I get the following error message: 创建第一个类并进行调试后,我收到以下错误消息:
Eine nicht behandelte Ausnahme des Typs "System.StackOverflowException" ist in mscorlib.dll aufgetreten. mscorlib.dll中的“典型.System.StackOverflowException”错误。
Eine nicht behandelte Ausnahme des Typs "System.StackOverflowException" ist in APPLICATION.exe aufgetreten. 可以在APPLICATION.exe中获取“ Typ。“ System.StackOverflowException”文件。
class Sprachpaket_ENG_Template01
{
MainWindow MW = new MainWindow();
public void Template01()
{
MW.checkBox_1_Bcc.Content = "Bcc:";
MW.checkBox_1_Cc.Content = "Cc:";
}
--> This causes the error: MainWindow MW = new MainWindow(); ->这会导致错误: MainWindow MW = new MainWindow();
From your edits and comments, you have this: 从您的编辑和评论中,您可以得到:
class Sprachpaket_ENG_Template01
{
// Create a new MainWindow whenever Sprachpaket_ENG_Template01 is created
MainWindow MW = new MainWindow();
}
class MainWindow()
{
public MainWindow()
{
// Create a new Sprachpaket_ENG_Template01 whenever MainWindow is created
Sprachpaket_ENG_Template01 ENG_01 = new Sprachpaket_ENG_Template01();
}
}
You have an infinite loop here, which is why you're getting a stack overflow. 您在这里有一个无限循环,这就是为什么您会得到堆栈溢出的原因。
You probably wanted to pass MainWindow as a parameter to the Sprachpaket_ENG_Template01 constructor: 您可能想将MainWindow作为参数传递给Sprachpaket_ENG_Template01构造函数:
class Sprachpaket_ENG_Template01
{
MainWindow MW;
public Sprachpaket_ENG_Template01(MainWindow mw)
{
MW = mw;
}
}
class MainWindow()
{
public MainWindow()
{
Sprachpaket_ENG_Template01 ENG_01 = new Sprachpaket_ENG_Template01(this);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.