Enumerable::ToList() - C++ Missing From MSDN

I would like to make one of these entries for every example I don't find on MSDN.
I'm not sure if the intention is to ignore C++ or if this was just expected to be too hard, too easy or too ugly for developers to grasp.

I have submitted this as Community Content on MSDN, also.


http://msdn.microsoft.com/en-us/library/bb342261.aspx

Here is the missing example for Enumerable::ToList();

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;

int GetLength(String^ str)
{
       return str->Length;
}

void main(void)
{
       array<String^>^ fruits = { "apple", "passionfruit", "banana", "mango",
                      "orange", "blueberry", "grape", "strawberry" };

       List<int>^ lengths =
              Enumerable::ToList(
                     Enumerable::Select(
                           gcnew List<String^>(fruits),
                                  gcnew Func<String^, int>(GetLength)
                           )
                     );

       for each(int length in lengths)
       {
               Console::WriteLine(length);
       }

/*
 This code produces the following output:

 5
 12
 6
 5
 6
 9
 5
 10
*/
}


posted @ Monday, February 22, 2010 4:30 PM
Print

Comments on this entry:

# imdrkbs6

Left by BillyFig at 7/23/2017 9:03 AM
Gravatar

Your comment:



(not displayed)

 
 
 
 

Live Comment Preview: