Do these statements mean the same thing?
int x { get; }
readonly int x;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In answer to your question: There is a difference between readonly and {get; }:
In
int x { get; }(which won’t compile as there’s no way to set x – I think you neededpublic int x { get; private set; }) your code can keep changing xIn
readonly int x;, x is initialised either in a constructor or inline and then can never change.