using System;
namespace ConsoleApplication_C_Sharp
{
class Program
{
class Test
{
readonly DateTime _dt;
public Test()
{
this._dt = DateTime.Now;
}
public DateTime GetDate()
{
return this._dt;
}
// Error CS0191 A readonly field cannot be assigned
// (except in a constructor or a variable initializer)
/*public DateTime SetDate()
{
this._dt = DateTime.Now;
}*/
}
static void Main(string[] args)
{
Test t = new Test();
Console.WriteLine(t.GetDate());
}
}
}
/*
run:
19/01/2017 09:25:46
*/