How to pass datetime variable

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello,

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.

Thanks,
James.
 
Hi James,

welcome to the great world of programming!

Here is a example:

public void PrintDateAndTime(System.DateTime DateAndTimeToPrint)
{
System.Console.WriteLine("Actual Date and Time: {0}",
DateAndTimeToPrint.ToString());
}

you invoke it that way:

PrintDateAndTime(System.DateTime.Now);

Asuming that you are working on a Console!

You should read the basics about functions/members/methods:
[Methods (C# Programming Guide)]
http://msdn.microsoft.com/en-us/library/ms173114.aspx

I higly recommend you to read the C# language reference, because
it is a great starting point for beginners:

[C# Programming Guide]
http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx

If you have more questions, feel free to ask them here:

Enjoy,...!

Regards

Kerem

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top