Error C2440 occurs when you convert a string array to the IEnumerable* interface implicitly in Visual C++ .NET or in Visual C++ 2005 (823936)
The information in this article applies to:
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
SYMPTOMSThe IEnumerable interface is used to expose the enumerator of a collection class. The enumerator supports a simple iteration over a collection. When you declare a string array,
and you want to enumerate its items, you can use the IEnumerable interface for the iteration. However, when you convert a string array to the IEnumerable* interface implicitly, you may receive the following error message:
error C2440: 'initializing' : cannot convert from
'System::String __gc * __gc[]' to 'System::Collections::IEnumerable __gc
*' RESOLUTIONTo resolve this problem, use the dynamic_cast <> operator
to perform type casting. The modified code is as follows:
String* myStringArray[]= {S"One",S"Two",S"Three"};
IEnumerable* myEnum = dynamic_cast<IEnumerable*> (myStringArray); STATUS Microsoft
has confirmed that this is a problem in the Microsoft products that are listed
at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 1/4/2006 |
---|
Keywords: | kberrmsg kbManaged kbLangCPP kbCollections kbprb KB823936 kbAudDeveloper |
---|
|