Partial Classes across different namespaces ?


V

vivekian

Hi,

Is there a way to have partial classes across different namespaces ?

namespace a.b.c
{
public partial class X
{
private void MyMethod () { }
}
}


using a.b.c

namespace a.b.c.d
{
public partial class X
{

}
}

Now , when the MyMethod has to be used in the second partial class ,
the compiler fails to recognize it. Where am i going wrong ?

thanks in advance ..
 
Ad

Advertisements

C

Carl Daniel [VC++ MVP]

vivekian said:
Hi,

Is there a way to have partial classes across different namespaces ?

namespace a.b.c
{
public partial class X
{
private void MyMethod () { }
}
}


using a.b.c

namespace a.b.c.d
{
public partial class X
{

}
}

Now , when the MyMethod has to be used in the second partial class ,
the compiler fails to recognize it. Where am i going wrong ?

a.b.c.X and a.b.c.d.X are two completely separate, unrelated classes, and
there's no way to make them act like the same class.

-cd
 
T

Tom Spink

vivekian said:
Hi,

Is there a way to have partial classes across different namespaces ?

namespace a.b.c
{
public partial class X
{
private void MyMethod () { }
}
}


using a.b.c

namespace a.b.c.d
{
public partial class X
{

}
}

Now , when the MyMethod has to be used in the second partial class ,
the compiler fails to recognize it. Where am i going wrong ?

thanks in advance ..
Hi,

Is there a way to have partial classes across different namespaces ?

No, there isn't because this doesn't make sense. A namespace seperates
types from each other, so that you can A) provide a logical seperation
between types and B) have types of the same name.

May I ask why would you need to have a partial class in two seperate
namespaces?
 
Ad

Advertisements

I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

vivekian said:
Hi,

Is there a way to have partial classes across different namespaces ?

If ypu have two classes under a different namespace they are different.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top