Previous Topic Next topic Print topic


Generics, Consuming - in COBOL and C#

C# COBOL
// Consuming a generic method via type inference

System.Tuple<int, int> result;
// Parameters are used to infer type
result = new System.Tuple.Create(1, 2);

//Consuming a generic collection
List<string> x = new List<string>();
int i;
for(i=0; i<101; ++i)
{
    x.Add(i.ToString());
}
foreach(string val in x)
{
    Console.WriteLine(val);
}
*> Consuming a generic method via type inference

01 result as type Tuple[binary-long binary-long].
*> Parameters are used to infer type
set result to type Tuple::Create(1 2)

*> Consuming a generic collection
01 x type List[string] value new List[string].
01 i binary-long.
01 val string.
procedure division.
    perform varying i from 0 by 1 until i greater than 100
       invoke x::Add(i::ToString)
    end-perform
    perform varying val through x
       display val
    end-perform
Previous Topic Next topic Print topic