How to: Convert from a STL/CLR Container to a .NET Collection

This topic shows how to convert STL/CLR containers to their equivalent .NET collections. As an example, we show how to convert a STL/CLR vector to a .NET ICollection<,T>, and how to convert a STL/CLR map to a .NET IDictionary<,TKey, TValue>,, but the procedure is similar for all collections and containers. To convert part of a container, call the make_collection function, and pass the begin iterator and end iterator of the STL/CLR container to be copied into the .NET collection. This template function takes an STL/CLR iterator as a template argument. The first example demonstrates this method. To convert an entire container, cast the container to an appropriate .NET collection interface or interface collection. The second example demonstrates this method. In this example, we create a STL/CLR vector and add 5 elements to it. Then, we create a .NET collection by calling the make_collection function. Finally, we display the contents of the newly created collection. In this example, we create a STL/CLR map and add 5 elements to it. Then, we create a .NET IDictionary<,TKey, TValue>, and assign the map directly to it. Finally, we display the contents of the newly created collection. STL/CLR Library ReferenceHow to: Convert from a .NET Collection to a STL/CLR Containerrange_adapter (STL/CLR) Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 18, 2016 @ 6:02 am