Can someone explain what is happening here.
Well, the compiler error message says it all, really, once you've got past the terminology. This line is invalid:
string s3 = s1 + s2;
You're declaring instance variables, and instance variable initializers (s1 + s2 here) aren't allowed to refer to other fields within the instance that's being created - or indeed the instance itself. Bear in mind that the above declaration is equivalent to:
string s3 = this.s1 + this.s2;
From section 10.5.5.2 of the C# 4 specification:
A variable initializer for an instance field cannot reference the instance being created. Thus it is a compile-time error to reference this in a variable initializer, because it is a compile-time error for a variable initializer to reference any instance member through a simple-name.
(Admittedly that's one of the more odder bits of wording in the spec...)
You have to put the logic into the constructor body instead:
class Class1
{
string s1 = "hi";
string s2 = "hi";
string s3;
public Class1()
{
s3 = s1 + s2;
}
}