+ 6

Learn C# readonly vs const

In the Learn C# chapter 'readonly' is stated that there are basically only 3 differences between const and readonly. But non off them adresses the static property. A const is always automatically static in C#. But I would guess readonly is not static and for every instance one can assign a different value. Am I right or is sth. that is readonly as well static? Anyway, I guess a statment about that in that chapter would be beneficial. /Cheers CL

5th Jan 2017, 6:23 PM
Edward F.
2 odpowiedzi
+ 5
Yes, you are right. readonly is NOT static by default, you can declare your variable like static readonly var; if you want it to be static too.
5th Jan 2017, 7:55 PM
Andrii Voloshchuk
Andrii Voloshchuk - avatar
0
Great question, good to know :))
7th Apr 2017, 2:03 PM
Magyar Dávid
Magyar Dávid - avatar