Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
is it posibble to write two classes in one name space in window forms .if possible tell me some example code in c#
Posted
Comments
[no name] 2-Jul-13 12:04pm    
Yes it is possible.
BiteForce 2-Jul-13 12:04pm    
Of course it is. You can define the namespace on the top of the class file.
Mahesh Bailwal 2-Jul-13 12:09pm    
you mean same file or namespace because by default if you add new class or form in visual studio to the project they always have same namespace.
Sergey Alexandrovich Kryukov 2-Jul-13 12:11pm    
It sound really weird. Let me tell you: such question could be asked only be a person who had never write any code, just because in the absolute majority of namespaces, more than one type is defined under each namespace. But, as you already asked 77 questions by now, it's hard to assume that you never wrote any code. Hence, I could only guess that you either: 1) actually wrote some code without understanding of what you are doing, 2) just confused about terminology (so, you might mean not the namespace, but something else, misnamed) or the concept of namespaces.
—SA

Yes, of course, always. "Windows.Forms" is totally irrelevant here. Everything which is not prohibited is allowed.

The question makes little sense, just because you can ask millions of questions like that in order just to get yes/no answer, which is utterly inefficient. Instead, all you need to try and see if it works. If it fails, you can read the error message and documentation. If you don't understand it, that's the only time to ask some question.

—SA
 
Share this answer
 
Yes:
C#
namespace MyNameSpace
    {
    public partial class MyFirstClass
        {
        ...
        }
    public partial class MySecondClass
        {
        ...
        }
    }
The two classes do not have to be in the same file. By default, every class you add to a Project is in the same Namespace, but you can change this by altering the namespace line of the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900