将表单对象值传递给静态方法
我需要获取一个表单对象值并将其传递给静态方法:
public void SetCalendarStartSafe(DateTime startDateSafe)
{
startDateSafe = calendarStart.Value;
}
private static DataTable GetData()
{
frmMain frm = new frmMain();
DateTime startDate = new frmMain();
frm.SetCalendarStartSafe(startDate);
}
但是,每当我尝试此方法时,我都会不断获取今天的当前日期,即使表单上指定的日历日期不同。如何从原始 frmMain 对象中获取用户指定的日历日期?预先感谢您的任何指导。
I need to take a form object value and pass it into a static method:
public void SetCalendarStartSafe(DateTime startDateSafe)
{
startDateSafe = calendarStart.Value;
}
private static DataTable GetData()
{
frmMain frm = new frmMain();
DateTime startDate = new frmMain();
frm.SetCalendarStartSafe(startDate);
}
However I keep getting today's current date whenever I try this approach, even if the specified calendar date on the form is different. How can I can the user-specified calendar date from the original frmMain object? Thanks in advance for any guidance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将从非静态代码中的某个位置调用 GetData() 吗?例如,来自 Form 中的某个事件.. 在该事件中将参数传递给静态方法 GetData(DateTime..)
you will be calling GetData() from somewhere in the code which is non-static? like for example from some event in the Form.. in that event pass the parameter to the static method GetData(DateTime..)
在那里,把这两个交换一下。任务的目的地位于左侧。
There, just swap those two around. The destination of the assignment is on the left.