[英]Method must have a return type on an InitializeComponent() method
I have the partial public class 我有部分公开课
namespace BugNetWPF
{
public partial class ReportScreen_IdRangeReport : Page
{
public GenerateReport(MainWindow mainWindow)
{
InitializeComponent();
}
}
}
The error is saying that the method must have a return type, any ideas how to fix this? 错误是说该方法必须具有返回类型,任何想法如何解决此问题?
What everyone else is saying about the return type is true, but I'm guessing this is what you actually want: 其他人都说返回类型是正确的,但是我猜这是您真正想要的:
namespace BugNetWPF
{
public partial class ReportScreen_IdRangeReport : Page
{
public ReportScreen_IdRangeReport(MainWindow mainWindow)
{
InitializeComponent();
}
}
}
The constructor needs to have the same name as the class. 构造函数必须与类具有相同的名称。
Change: 更改:
public GenerateReport(MainWindow mainWindow)
{
InitializeComponent();
}
on: 上:
public void GenerateReport(MainWindow mainWindow)
{
InitializeComponent();
}
If your GenerateReport
method doesn't return anything the return type should be declared as void
. 如果您的
GenerateReport
方法不返回任何内容,则返回类型应声明为void
。
You have provided a constructor called GenerateReport
to class ReportScreen_IdRangeReport
, constructor must match class 您已为类
ReportScreen_IdRangeReport
提供了一个名为GenerateReport
的构造ReportScreen_IdRangeReport
,该构造函数必须与类匹配
namespace BugNetWPF
{
public partial class ReportScreen_IdRangeReport : Page
{
public ReportScreen_IdRangeReport(MainWindow mainWindow)
{
InitializeComponent();
}
}
}
or 要么
namespace BugNetWPF
{
public partial class GenerateReport : Page
{
public GenerateReport (MainWindow mainWindow)
{
InitializeComponent();
}
}
}
The problem is that your GenerateReport
method doesn't declare a return type. 问题在于您的
GenerateReport
方法未声明返回类型。 If it doesn't return anything the return type should be declared as void
. 如果不返回任何内容,则返回类型应声明为
void
。
public void GenerateReport(MainWindow mainWindow)
{
InitializeComponent();
}
You normally call InitializeComponent in your constructor. 您通常在构造函数中调用InitializeComponent。 Like
喜欢
public ReportScreen_IdRangeReport(MainWindow mainWindow)
{
InitializeComponent();
}
Then Your method ( if you really need this
i doubt that) 然后您的方法(
if you really need this
我会怀疑)
public GenerateReport(MainWindow mainWindow)
{
doesn't have a return type and it isn't allowed. 没有返回类型,因此不允许。
It should have a return type of void
if you don't want to return anything. 如果您不希望返回任何内容,则返回类型应为
void
。
public void GenerateReport(MainWindow mainWindow)
{
See void in front of your method name: 在您的方法名称前看到void :
namespace BugNetWPF
{
public partial class ReportScreen_IdRangeReport : Page
{
public void GenerateReport(MainWindow mainWindow)
{
InitializeComponent();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.