Do you know how to pass date arguments in C#?
VB Example
Public Sub Test (datTest As Date)
MsgBox(datTest.ToString())
End Sub
Public Sub TestCall()
Me.Test(#1/1/2001#)
End Sub
In this example, the TestCall procedure wraps the # qualifer around the
date. What is the equivalent in C#
public void Test (DateTime datTest)
{
MessageBox.Show(datTest.ToString());
}
public void TestCall()
{
this.Test(#1/1/2001#);
}
I have looked at dozens of samples on-line and multiple books, but nothing
shows how to do this and it is starting to irritate me. This is basic stuff,
but it is not documented anywhere that Google can find...
"Alberto Poblacion" wrote:
"James" <bo*************@gmail.comwrote in message
news:32**********************************@x35g2000 hsb.googlegroups.com...
I am a beginner in C# programming and I just want to know how we can
pass a datetime variable in a method. can anyone please help me
regarding this.
I assume that you already know how to declare the method and that your
problem is that you don't know how to insert into your code a given date,
such as "September 28th, 2008". One of the ways to do it is by means of one
of the constructors of the DateTime class, which takes year, month and day
as parameters:
DateTime dateToPass = new DateTime(2008,9,28);
MyMethod(dateToPass);
.....
private void MyMethod(DateTime argument)
{
//Here 'argument' contains the date that you passed.
}