0

In this scenario, i have this first case

public class WebHostBuilder : IWebHostBuilder
{
    private IConfiguration _config;
    private ILoggerFactory _loggerFactory;
}

and the other one is

public class WebHostBuilder : IWebHostBuilder
{
    private IConfiguration _config {get; set;};
    private ILoggerFactory _loggerFactory {get; set;};
}

My question is which of the two is correct or most commonly used?

datkom
  • 1,472
  • 1
  • 11
  • 11
  • 2
    If it's private, it's usually a field (first case). Not always, but much more often. – Evk Nov 01 '16 at 11:25
  • @Tinwor if the second one is correct then why did microsoft use the first method? Here is the full code [link](https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs) – datkom Nov 01 '16 at 11:26
  • 1
    Private property? Are you sure? The point of having properties is to make them available outside if a class – Ted Nov 01 '16 at 11:27
  • 1
    They're both correct. The one to use depends on the context/logic. – Big Daddy Nov 01 '16 at 11:27
  • My fault. I haven't seen the private access modifiers. To swwet yesterday evening – Tinwor Nov 01 '16 at 11:30
  • Please read [What is the difference between a Field and a Property in C#?](http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c) – Jim Nov 01 '16 at 11:31

0 Answers0