如何初始化以开始和结束日期为参数的t1对象?错误行是t1.store("task1","gui design",2014 01 01,2014 04 04,"completed").如何将日期参数传递给存储方法...谁能帮助我找出答案?
class Program
{
static void Main(string[] args)
{
Task t1 = new Task();
Task t2 = new Task();
t1.store("task1","gui design",2014 01 01,2014 04 04,"completed");
}
}
class Task
{
string _Tid;
string _tn;
DateTime _sdate;
DateTime _edate;
string _status;
public void store(string tid,string tname, Date start,Date end,string sts)
{
this._Tid = tid;
this._tn = tname;
this._sdate = start;
this._edate = end;
this._status = sts;
}
public void print()
{
Console.WriteLine("\n {0}\t{1}\t{2}\t{3}\t{4}",this._Tid,this._tn,this._sdate,this._edate,this._status);
}
}
}
Date
以及提供的构造函数.这里的任何人都不可能回答这个问题.最有可能涉及诸如之类的代码new Date(...)
,然后您必须弄清楚如何将拥有的值放入该构造函数的参数中.Date
不是内置的.NET类型.这种类型要么来自您自己的代码,要么来自您正在使用的库,但是除非我们知道它来自哪个库,或者可以看到其构造函数的代码,否则无法回答您的问题.您可以通过以下方法创建DateTime
var dt1 = new DateTime(2014,10,25);
var dt2 = DateTime.Parse("2014/10/25");
并将方法签名更改为此
public void store(string tid,string tname, DateTime start,DateTime end,string sts)
如果要确保只使用DateTime对象的Date部分,则可以使用start.Date或end.Date
DateTime
,Date
不是.NET类型,这里没有任何人可以回答他的问题.new Date(
,会发生什么情况?您会从Visual Studio获得帮助吗?DateTime
因此他将需要一个DateTime对象作为参数Date
,不是DateTime
.t1.store("task1","gui design",Convert.ToDateTime(01/01/2014),Convert.ToDateTime(04/04/2014),"completed");
您的参数不正确.您必须使用以下数字:new Date(2014 01 01)并通过tow方法;
class Program
{
static void Main(string[] args)
{
Task t1 = new Task();
Task t2 = new Task();
t1.store("task1","gui design",new DateTime(2014, 01, 01),new DateTime(2014 ,04 ,04),"completed");
}
}
class Task
{
string _Tid;
string _tn;
DateTime _sdate;
DateTime _edate;
string _status;
public void store(string tid, string tname, DateTime start, DateTime end, string sts)
{
this._Tid = tid;
this._tn = tname;
this._sdate = start;
this._edate = end;
this._status = sts;
}
public void print()
{
Console.WriteLine("\n {0}\t{1}\t{2}\t{3}\t{4}", this._Tid, this._tn, this._sdate, this._edate, this._status);
}
}
由于您使用的是自定义Date
实现,因此调用该方法的正确方法如下:
t1.store("task1","gui design", new Date(2014, 01, 01), new Date(2014, 04, 04) ,"completed");
how can i initialize t1 object which has start and end dates as parameters? the error line is t1.store("task1","gui design",2014 01 01,2014 04 04,"completed") . how can i pass date argument to store method... can anyone help me to find out?
class Program
{
static void Main(string[] args)
{
Task t1 = new Task();
Task t2 = new Task();
t1.store("task1","gui design",2014 01 01,2014 04 04,"completed");
}
}
class Task
{
string _Tid;
string _tn;
DateTime _sdate;
DateTime _edate;
string _status;
public void store(string tid,string tname, Date start,Date end,string sts)
{
this._Tid = tid;
this._tn = tname;
this._sdate = start;
this._edate = end;
this._status = sts;
}
public void print()
{
Console.WriteLine("\n {0}\t{1}\t{2}\t{3}\t{4}",this._Tid,this._tn,this._sdate,this._edate,this._status);
}
}
}
Date
is and what constructors it provides. There's no way anyone here can answer this question. Most likely it involves code like new Date(...)
, and then you have to figure out how to put the values you have into the parameters to that constructor.Date
is not a built-in .NET type. This type either comes from your own code, or from a library you're using, but unless we either know which library it came from, or can see the code for its constructor(s), there's no way to answer your question.You can create DateTime via these methods
var dt1 = new DateTime(2014,10,25);
var dt2 = DateTime.Parse("2014/10/25");
and change the method signature to this
public void store(string tid,string tname, DateTime start,DateTime end,string sts)
and if you want to be sure that you only use the Date part of DateTime object you can use start.Date or end.Date
DateTime
, he's using Date
, which is not a .NET type, there's no way anyone here can answer his question.new Date(
, do you get help from Visual Studio telling you what goes where?DateTime
so he would need a DateTime object as paramDate
, not DateTime
.t1.store("task1","gui design",Convert.ToDateTime(01/01/2014),Convert.ToDateTime(04/04/2014),"completed");
your parameter is incorrect. you must use this figure: new Date(2014 01 01) and pass tow method;
class Program
{
static void Main(string[] args)
{
Task t1 = new Task();
Task t2 = new Task();
t1.store("task1","gui design",new DateTime(2014, 01, 01),new DateTime(2014 ,04 ,04),"completed");
}
}
class Task
{
string _Tid;
string _tn;
DateTime _sdate;
DateTime _edate;
string _status;
public void store(string tid, string tname, DateTime start, DateTime end, string sts)
{
this._Tid = tid;
this._tn = tname;
this._sdate = start;
this._edate = end;
this._status = sts;
}
public void print()
{
Console.WriteLine("\n {0}\t{1}\t{2}\t{3}\t{4}", this._Tid, this._tn, this._sdate, this._edate, this._status);
}
}
Since you're using a custom Date
implementation, the correct way to call that method is like this:
t1.store("task1","gui design", new Date(2014, 01, 01), new Date(2014, 04, 04) ,"completed");
本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文