✔ Simple code structure question
Let's say I have interface "IShapes" in file Shapes.cs
Now, I'd like to create 3 more classes. Circle, square, and triangle.
Should I create 3 more files for each class
or rather put them all under the Shapes.cs file?
4 Replies
That's the convention, yes
One class per file, file named like the class
(or interface, or enum, or record... you get the idea)
So
IShape.cs
, Circle.cs
, Square.cs
and Triangle.cs
in your case
That contain, respectively, interface IShape
, class Circle
, class Square
and class Triangle
What is the point of namespaces then? From what I've learnt, they are used to group classes together (though my notion of namespaces might be wrong, I'd be delighted to know what their real use is)
Yes, that is the use of a namespace
And namespaces usually follow the folder structure
So in a
you would have
Ah, well, I thought that namespaces could only apply to one class, thank you for clearing that up!