Nmaespace

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to create a namespace. I don't know how to do it. I add a class in
my project. Should I add keyword namespace myNmaspace to it. or how can I do
it.

I want three files

myNmaespace.fileA
myNmaespace.fileB
myNmaespace.fileC
Where fileA.ca, fileB.cs,fileC.cs are my Classfiles.
 
I want to create a namespace. I don't know how to do it. I add a class in
my project. Should I add keyword namespace myNmaspace to it. or how can I do
it.

I want three files

myNmaespace.fileA
myNmaespace.fileB
myNmaespace.fileC
Where fileA.ca, fileB.cs,fileC.cs are my Classfiles.

Just surrond the class definition with the namespace definition, like
this:

namespace MyNameSpace
{
class MyClass
{
...
}
}
 
re:
!> I want to create a namespace. I don't know how to do it.

Just write the namespace's name in the different files,
and place all the files in the App_Code directory.

namespace GeometricShapes
{
public class Square
{
public double Side;
}
}

class Geometry
{
void ShowSquare()
{

// in this class you call the Square class of the GeometricShapes namespace :

GeometricShapes.Square sqr = GeometricShapes.Square();
sqr.Side = 24.55;
}
}

If you want a *class* to span several files, make sure they're declared as *partial* classes :

With Partial declarations for a class you can split the class into several files:

MyClass1.cs:

public partial class MyClass
{
public void method1()
{
// ...whatever you code here
}
}


MyClass2.cs:

public partial class MyClass
{
public void method2()
{
}
}



Juan T. Llibre, asp.net MVPasp.net faq : http://asp.net.do/faq/foros de asp.net, en español :
 
Back
Top