I create objects by initializing the fields in this way:
class Example
{
public int a;
public int b;
}
var obj = new Example
{
a = stream.ReadInt(),
b = stream.ReadInt()
};
Is it always for field "a" to be initialized before field "b"? Otherwise, an unpleasant error can occur when the values from the stream are subtracted in a different order. Thanks!
UPD: In the comments, many did not understand what I mean. I will clarify the question. Do these records always be identical in behavior on different (.NET, Mono, etc) compilers?
First:
var obj = new Example
{
a = stream.ReadInt(),
b = stream.ReadInt()
};
Second:
var a = stream.ReadInt();
var b = stream.ReadInt();
var obj = new Example
{
a = a,
b = b
};
var obj = new Example(); obj.a = stream.ReadInt(); obj.b = stream.ReadInt();
. Expecting that to work reliably is the same as expectingConsole.WriteLine("First:" + stream.ReadInt()); Console.WriteLine("Second:" + stream.ReadInt())
to work reliably in a well-defined manner ~ it does! :) – Leucocyte