How many classes can I put in the same code?

1

How many "classes" can I add to my code?

Let's say I have the following existing command block:

namespace _06_ByteBank
{
    public class Cliente
    {
        private string _cpf;

    public string Nome { get; set; }
    public string CPF
    {
        get
        {
            return _cpf;
        }
        set
        {
            // Escrevo minha lógica de validação de CPF
            _cpf = value;
        }
    }
    public string Profissao { get; set; }
  }
}

To add another "class" would I write under this block or inside it?

    
asked by anonymous 07.12.2018 / 15:28

1 answer

4

As many as you want. There is no theoretical limit. I can assure you that you will have other problems before reaching any technical limits (which will be more limiting of memory available to the compiler, and we already have a lot).

The problem is that you are thinking the wrong way. You must learn to organize code. Understand the problem and make the code as possible to solve it. Learning this takes a long time, needs a lot of dedication, and it's a lot harder than people realize. Doing it anyway and putting it to work is easy, writing quality code and lasting it is a lot more complicated, and the observation I have is that most people who are starting lately are not learning this because they just want to see the result, no matter how. In the long run this does not work.

You do not need to put another class there. You can create another file with the new class. Of course, it depends on the case, you will have to learn when to put it in the same file or not.

But if you want to insist you have to put c class inside the block of namespace , I mean, it's probably possible to put off, but it's unlikely I wanted this. You may even want to create another% with% off. Or even nest them.

You can repeat namespace , it's just a last name. Even in different files all types that use the same namespace name will be part of it.

It would be nice to learn some C # naming standards to get the code organized.

    
07.12.2018 / 15:46