0

I was wondering what the difference between an internal class with internal fields and an internal class with public fields in C# is. I know that internal is for library intern access only. But if my class is internal, then public attributes will never be available outside the library because the class isn't. Or am I wrong? I currently have many classes as models in my project that I want to keep internal until I need them outside of the library (then I would make them public). Is it against clean code to keep the fields in these internal libraries public to make it easier if I maybe convert the models I need to public?

Aerith
  • 98
  • 1
  • 10
  • 1
    Do you mean ["properties"](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties) or perhaps ["members"](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/members) instead of ["attributes"](https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/reflection-and-attributes/)? – ProgrammingLlama Apr 07 '23 at 06:32
  • 1
    It seems that your question is essentially opinion-based since you're asking us whether it's better to also make the (members) internal or not when your class is internal. I'd say that arguments could be made either way. – ProgrammingLlama Apr 07 '23 at 06:34
  • I meant fields. I will change it in the question. Thank you – Aerith Apr 07 '23 at 06:35
  • @ProgrammingLlama My main goal is to understand if there is any difference. – Aerith Apr 07 '23 at 06:37
  • 2
    No, there is no difference. – Guru Stron Apr 07 '23 at 06:37
  • 3
    Effectively, there is no difference. It's a philosophical question as to which is more correct. Personally, I would make the members `public` but I can't really say that making them `internal` is wrong. – jmcilhinney Apr 07 '23 at 06:45
  • 1
    Fields should in general be private, not public or internal (with the prossible exception of readonly fields) – Klaus Gütter Apr 07 '23 at 07:05

0 Answers0