Type casting from one namespace to the other.

J

John Smith

Hi All,

(I first posted this question on the csharp.general but got no response, and
since this NG is more active, so I repost it here)

I have two enum definitions from two different namespaces:

namespace ns1
{
public enum e1{

e1a, e1b ......

}

}



namespace ns2
{
public enum e2{

e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)

}

}

Let say in ns1 I have created a array such that

e1[] e1Array=new e1[10];

If I passed the e1Array into a routine, is it possible to cast it into an n2
array, e.g.

e2 e2Array = (e1[]) e1Array. <--- not working.

Anyway get do this?



TIA.
 
H

Horacio N. Hdez.

Hi All,

(I first posted this question on the csharp.general but got no response, and
since this NG is more active, so I repost it here)

I have two enum definitions from two different namespaces:

namespace ns1
{
public enum e1{

e1a, e1b ......

}
}

namespace ns2
{
public enum e2{

e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)

}
}

Let say in ns1 I have created a array such that

e1[] e1Array=new e1[10];

If I passed the e1Array into a routine, is it possible to cast it into an n2
array, e.g.

e2 e2Array = (e1[]) e1Array. <--- not working.

Anyway get do this?

TIA.

Hi,
I think that you can't make a cast to enums
you should try to play with the numbers values of the enums, remember
that the elements of enums are internaly numbers
 
J

John Smith

Thanks, Horacio.

Actually I was trying to do something like:

// bassically a switch wrapper

e1[] getSet()

{

if (wante1) // set somewhere

return getSetFrome1();

else

return getSetFrome2(); <--- that is my problem if I want to return the e2
array

in e1 namespace, could the cast be used?

}

Namespace e1ns

{

Public e1[] getSetFrome1()

{

Return new e1[x];

}

}

Namespace e2ns

{

Public e2[] getSetFrome2()

{

Return new e2[y];

}

}

Horacio N. Hdez. said:
Hi All,

(I first posted this question on the csharp.general but got no response,
and
since this NG is more active, so I repost it here)

I have two enum definitions from two different namespaces:

namespace ns1
{
public enum e1{

e1a, e1b ......

}
}

namespace ns2
{
public enum e2{

e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)

}
}

Let say in ns1 I have created a array such that

e1[] e1Array=new e1[10];

If I passed the e1Array into a routine, is it possible to cast it into an
n2
array, e.g.

e2 e2Array = (e1[]) e1Array. <--- not working.

Anyway get do this?

TIA.

Hi,
I think that you can't make a cast to enums
you should try to play with the numbers values of the enums, remember
that the elements of enums are internaly numbers
 
Top