class properties that can be assigned only when creating object?
<p>It's possible in C# to write things such way:</p>

<pre><code>Instrument instr = new Instrument { ClassCode = "Hello", Ticker = "World" };
</code></pre>

<p>However to do that you have to add <code>set;</code> in the corresponding class:</p>

<pre><code>class Instrument
{
    public string ClassCode { get; set; }
    public string Ticker { get; set; }
}
</code></pre>

<p>This means that later someone can accidentally change value:</p>

<pre><code>instr.ClassCode.set = "Destroy"
</code></pre>

<p>And I don't want to allow that. I.e., from one hand I want a readonly property, from another hand i want to create objects like that:</p>

<pre><code>Instrument instr = new Instrument { ClassCode = "Hello", Ticker = "World" };
</code></pre>

<p>I'm not sure if this is possible. Probably I should use fields or something else instead of properties. I only want to have the syntax of the last sentence but keep things readonly at the same time.</p>

<p><strong>upd:</strong> In short no, readonly properties are not allowed in any way. Regular constructor and "get" should be used in this case.</p>
