I have this snippet of code. Why does C# know what Path
class is without giving me an error given that Path
is in the System.IO
, logically, I should include it. However, Visual Studio 2022 did not yell at that. And another question is does using Some.Namespace
automatically import other files in the file structure in C#? Like in PHP, when we want to use some classes from another file, we have to import that file use require_once
or in Python, we use the import
statement.
using System.Text.Json;
namespace ContosoCrafts.Website.Services
{
public class JsonFileProductService
{
public JsonFileProductService(IWebHostEnvironment webHostEnvironment)
{
WebHostEnvironment = webHostEnvironment;
}
public IWebHostEnvironment WebHostEnvironment { get; }
private string JsonFileName
{
get { return Path.Combine(WebHostEnvironment.WebRootPath, "data", "products.json"); }
}
}
}