C# doesn't have optional parameters in this sense. If you want to make addedOn optional, you should write an overload that doesn't require that parameter, and passes DateTime.Now to the two-argument version.
There is a workaround for this, taking advantage of nullable types and the fact that null is a compile-time constant. (It's a bit of a hack though, and I'd suggest avoiding it unless you really can't.)
public void SomeClassInit(Guid docId, DateTime? addedOn = null)
{
if (!addedOn.HasValue)
addedOn = DateTime.Now;
//Init codes here
}
In general, I'd prefer the standard overloading approach suggested in the other answers:
public SomeClassInit(Guid docId)
{
SomeClassInit(docId, DateTime.Now);
}
public SomeClassInit(Guid docId, DateTime addedOn)
{
//Init codes here
}
I guess that you did not really want addedOn = DateTime.Now because that would suggest you never get any result as everything would be added before 'Now'. :)
A default DateTime can be set like this:
public void SomeClassInit(Guid docId, DateTime addedOn = default(DateTime))
Update
If you deal with SQL Server, do not forget that it doesn't accept default(DateTime) what is 1/1/0001. SQL Server's minimal DateTime is 1/1/1753 (explanation). SQL's DateTime2 accepts 1/1/0001, though.