|
|
|||
Help me to understand classes in C# 4.0
Hello, i'm kind of new in learning C#, bought a book, Programming C# 4.0, i'm just at chapter 5, and i'm wondering, the classes most be defined in a single file for each one or a single file can contain several classes,
Thanks a lot for your time and support. 2 Replies
Yes, a file may contain more than one class.
Here's an example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace WindowsFormsApplication1 { class TestClasses { public string getName() { return "TestClasses"; } } class TestClasses2 { public string getName() { return "TestClasses2"; } } } You can paste that code into a new "class file" and then use both defined classes in your project. With that said, unless you have a good reason to place more than one class in any given file, you should avoid doing so, because it can complicate maintenance. |
|||
|