A
Allen Maki
Why can I get the index of the item of the array when I use string*, but
can not get the index of the array when I use any other type (such as
Int32)?
This code will compile perfectly, but if I replace String* with Int32, the
code would not compile?
The code using String* type:
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int _tmain()
{
String* Items[] = { S"Dog", S"Cat", S"Elephant", S"Gerbil", S"Dog",
S"Horse", S"Pig", S"Cat" };
String* Item = S"Elephant";
int pos = Array::IndexOf(Items, Item);
Console::WriteLine(S"Index of Item in Items is {0}", __box(pos));
return 0;
}
The code using Int32
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int _tmain()
{
Int32 Items [] = {1,3,5,7,4,9,6};
Int32 Item = 7;
int pos = Array::IndexOf(Items, Item);
Console::WriteLine(S"Index of Item in Items is {0}", __box(pos));
return 0;
}
can not get the index of the array when I use any other type (such as
Int32)?
This code will compile perfectly, but if I replace String* with Int32, the
code would not compile?
The code using String* type:
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int _tmain()
{
String* Items[] = { S"Dog", S"Cat", S"Elephant", S"Gerbil", S"Dog",
S"Horse", S"Pig", S"Cat" };
String* Item = S"Elephant";
int pos = Array::IndexOf(Items, Item);
Console::WriteLine(S"Index of Item in Items is {0}", __box(pos));
return 0;
}
The code using Int32
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
int _tmain()
{
Int32 Items [] = {1,3,5,7,4,9,6};
Int32 Item = 7;
int pos = Array::IndexOf(Items, Item);
Console::WriteLine(S"Index of Item in Items is {0}", __box(pos));
return 0;
}