Need Help Please in counting a String object in Array
#using <mscorlib.dll>
#using <System.dll>
#include <algorithm>
#using <System.Windows.Forms.dll>
using namespace System;// Array class
using namespace System::Collections;
using namespace System::Windows::Forms;
// Object class contains a ToString method:
void showSingleManagedArray(Object * arr[], String * name)
{
// Begin with an empty String
String * str = S"";
// Add to the existing String (str)
// array value to the Concat method
// assigning the result back to str.
for (int i=0; i<arr->Length; i++)
if (arr[i] != 0) // check for null reference
str = String::Concat(str, arr[i]->ToString(), S"\n");
// Display the array elements that are stored in the String:
MessageBox::Show(str, name);
}
int __stdcall WinMain()
{
String * strArray[] = new String * [4];
strArray[0] = S"This was";
strArray[1] = S"very challenging";
strArray[2] = S"and";
strArray[3] = S"grey matter intensive";
showSingleManagedArray(strArray, S"Original String Array");
// invoke the Contains method:
if (strArray->Contains(S"and"))
MessageBox::Show(
S" and ", S"Found");
//if object not found
else
MessageBox::Show(
S"and not found", S"Not Found");
int index = Array::IndexOf(strArray, S"and");
if (index != -1)
MessageBox::Show(
index.ToString(),
S" and was found at index!"
);
MessageBox::Show(
strArray->Count.ToString(),
S"Showing Count"
);
return(0);
}

