从VB Collection转换为Int

时间:2012-11-06 23:17:03

标签: c# casting

你在这里看到错误的代码吗?我在使用INT变量的foreach循环上得到一个InvalidCastException:

 Microsoft.VisualBasic.Collection oHeaders = GetFieldIdsByName(msREPORT_HEADER);

foreach (int FieldId in oHeaders)

2 个答案:

答案 0 :(得分:2)

foreach (object FieldId in oHeaders)
{
    int value = Int32.Parse(FieldId.ToString());
}

答案 1 :(得分:1)

foreach (int i in oHeaders.Cast<int>())
{
     //TODO: your action here.
}