C#C
C#10mo ago
Faker

✅ using keyword as a directive

Hello guys, I'm a bit confused of how the
using
keyword is used with a namespace. Say I created a new project. At the root of that project we have a solution and inside that solution we have our project folder. Now, the namespace refers to the individual project folder we have?

Consider the picture for example. The namespace is the same for every .cs file in a particular project? Why can't we do using LibraryManagement.BankAccount? What I'm trying to say is, look inside the LibraryManagementFolder and import the BankAccount class but this is incorrect to interpret it like that?

Second thing, consider the following code:

C#
namespace LibraryManagement;

public class BankAccount
{
    public string Number { get; }
    public string Owner { get; set; }
    public decimal Balance { get; }
    
    public BankAccount(string name, decimal initialBalance)
    {
        Owner = name;
        Balance = initialBalance;
    }

    public void MakeDeposit(decimal amount, DateTime date, string note)
    {
        
    }

    public void MakeWithdrawal(decimal amount, DateTime date, string note)
    {
        
    }
}


When we don't use top-level statement, the namespace should explicitly been set? What the difference between a namespace and the
using
keyword directive here please
36D41A2E-0C7B-4D5D-8F21-C8A53656BF01.png
Was this page helpful?