473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Type casting from one namespace to the other.

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.

Jan 31 '07 #1
2 2437
On 31 ene, 17:58, "John Smith" <j...@js.comwrote:
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
Jan 31 '07 #2
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." <hn******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
On 31 ene, 17:58, "John Smith" <j...@js.comwrote:
>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


Jan 31 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cgacc20 | last post by:
I have a c struct from old code that cannot be modified and I am trying to write a wrapper C++ class around it. This class is often passed as a pointer to some c functions of a library and I...
5
by: Suzanne Vogel | last post by:
** Isn't the 'static_cast' operator the same as traditional type casting? ie, Aren't the following ways of getting b1, b2 the same? // 'Derived' is derived from 'Base' Derived* d = new...
1
by: JohnK | last post by:
under the covers is type casting in VB.Net the same as C# ? myObject = CType(..,..) in VB.Net vs myObject = (SomeClass)aObject
9
by: Roman Mashak | last post by:
Hello, All! Given the sample piece of code I have: #include <stdio.h> #include <string.h> int main(void) { short int i, j;
23
by: René Nordby | last post by:
Hi there, Is there anyone that knows how to do the following? I have a class A and a class B, that 100% inherits from class A (this means that I don't have other code in class B, than...
16
by: Enekajmer | last post by:
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 }
31
by: dragoncoder | last post by:
Consider the code class A { private: int a; }; int main(void) { A x; int* ptr = (int*)&x;
6
by: antonyliu2002 | last post by:
Hi, guys, I am using Visual Web Developer Express 2005 for my web application. I wrote a simple class called MyTestClass.cs and put it in the App_Code folder. I compiled it to library from...
11
by: Frederic Rentsch | last post by:
Hi all, If I derive a class from another one because I need a few extra features, is there a way to promote the base class to the derived one without having to make copies of all attributes? ...
2
by: stmfc | last post by:
in java, class types do not allow casting. to convert one to other, there must be special methods (except inheritance) does c++ allow class type casting? (except inheritance)
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.