如何循环浏览一个集合?
我正在使用 Fujitsu/Alchemy 编译器的试用版,并且从供应商那里获得了缓慢而糟糕的支持。
我基本上想将一个列表从 C# 传递给 COBOL,然后让 COBOL 使用它并可能更新它。
在 C# 中,遍历集合的常规方法是使用“foreach”构造。
但是,C#“foreach”构造是以下内容的快捷方式:
private static void test1()
{
List<IDMSMapField> list1 = new List<IDMSMapField>();
int listSize = list1.Count;
// was just checking exact variablename and case here to copy into COBOL code.
int itemNumber = 0;
System.Collections.Generic.List<IDMSMapField>.Enumerator enumerator1 = list1.GetEnumerator();
while (enumerator1.MoveNext())
{
Console.Write("Okay" + enumerator1.Current);
}
}
如果你能帮我弄清楚如何声明这个类,我可以用 COBOL 写这个:
System.Collections.Generic.List<IDMSMapField>.Enumerator
“枚举器”结构记录在 Microsoft 的 MSDN 站点上。
它告诉“枚举器”是一个结构,而不是一个类!
从我在手册“CreatingCOBOLfromDotnetFrameworkDox.pdf”中可以看出,结构被定义为 COBOL 存储库中的类。
手册中的示例:
Define specifiers for structure in REPOSITORY, and any struct members:
CLASS STRUCT-name AS "struct-namespace"
PROPERTY PROP-struct-member AS "external-property-name"
Handle structures like classes. E.g. object to store a struct instance:
01 struct-object OBJECT REFERENCE STRUCT-name.
下面,我将重复我尝试过的一些变体,但由于“无法解决”错误,这些变体都无法编译。如果你能告诉我如何正确声明这一点,我认为我们可以继续前进。
1.
REPOSITORY.
CLASS CLASS-LIST AS "System.Collections.Generic.List<>"
CLASS STRUCT-Enumerator AS "System.Collections.Generic.List<>.Enumerator"
.
第二行错误:
错误 JMN1795I-S:无法解析命名引用“System.Collections.Generic.List<>.Enumerator”。
完全相同的错误:
REPOSITORY. CLASS CLASS-LIST AS "System.Collections.Generic.List<>" CLASS STRUCT-Enumerator AS "System.Collections.Generic.List<T>.Enumerator" .
错误 JMN1795I-S:无法解析命名引用“System.Collections.Generic.List.Enumerator”。
同样的错误:
存储库。CLASS CLASS-LIST AS "System.Collections.Generic.List<>" CLASS STRUCT-Enumerator as "System.Collections.Generic.List.Enumerator" 。
错误 JMN1795I-S:无法解析命名引用“System.Collections.Generic.List.Enumerator”。
另一种选择是将它视为一个数组,但我也坚持这一点。
REPOSITORY.
CLASS LIST-IDMSMapField AS "System.Collections.Generic.List<>[]"
CLASS CLASS-IDMSMapField AS "Lightyear.ERCB.IDMSDC.IDMSMapField"
CLASS CLASS-LIST-IDMSMapField EXPANDS LIST-IDMSMapField USING CLASS-IDMSMapField.
METHOD-ID. TW1DR4000-PF06 AS "TW1DR4000_PF06".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MapFieldItem USAGE OBJECT REFERENCE CLASS-IDMSMapField.
LINKAGE SECTION.
01 MapFieldList USAGE OBJECT REFERENCE CLASS-LIST-IDMSMapField.
PROCEDURE DIVISION...
...
SET MapFieldItem TO MapFieldList(1).
错误 JMN2671I-S: ':' 必须在引用修饰符中指定。':' 假设。
我认为编译器可能将 (1) 视为子字符串操作。