0

When i have a private field in c#, let's say private string a, which is used in the constructor like this:

a = "1";
Console.WriteLine(a);

and i create a public property via: Ctrl + R + E Visual Studio 2015 automtically replaces all private fields with the public one, means:

A = "1";
Console.WriteLine(A);

Why do VS has this default behaviour, and can it be turned off?

Thank you!

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • I don't quite get it, sorry. Did you mean `When i have a private *field*` instead of `When i have a private property`? – Christian.K Sep 14 '15 at 11:44
  • Yep, i will change the question – BendEg Sep 14 '15 at 11:44
  • Are you using ReSharper? In that case, when you press Ctrl+R+E, there's a dialog where you can set the visibility of your property. – Dmytro Shevchenko Sep 14 '15 at 11:45
  • OK, so essentially you refactor a field into a property then. Well, maybe someone thought that the default accessibility for a property should be, or rather would be, public. Otherwise you wouldn't have turned that field into a property in the first place. Just saying... – Christian.K Sep 14 '15 at 11:45
  • No, clean visual studio enterprise 2015 – BendEg Sep 14 '15 at 11:45
  • Because it just another one of the dozens of Roslyn bugs in VS2015. Type Ctrl+. instead and it will do less damage. – Hans Passant Sep 14 '15 at 11:49
  • Use [ctrl] + [.] to view Quick Actions, and choose the second form of "Encapsulate Field". Slightly more cumbersome, but it will do what you want. No shortcut available though. – Willem van Rumpt Sep 14 '15 at 11:49
  • Ok, do i have to report the behaviour? – BendEg Sep 14 '15 at 11:49

0 Answers0