Is there a way to have a private readonly field in a class that could be assigned a value anywhere in the class, but only once??
That is, I am looking for a private read
I think I achieved a way to do it, if it is done in the constructor. It could also be on the variable declaration line. If done outside those contexts, you will receive an error: A readonly field cannot be assigned to (except in a constructor or a variable initializer)
public class BillLine
{
public BillLine(Bill bill)
{
m_Bill = bill;
}
private readonly Bill m_Bill;
public Bill Bill
{
get { return m_Bill; }
//supposed to be set only in the constructor
}
//(...)
}