This article describes how you can write constructors with different signatures in COBOL .NET classes.
Problem:
You need to define different constructors in a COBOL .NET class that have different signatures.
Resolution:
The following code gives an example of a COBOL .NET class that has different constructors:
class-id. Class1 as "ClassLibrary1Cobol.Class1".
environment division.
configuration section.
repository.
static.
working-storage section.
end static.
object.
working-storage section.
method-id. NEW.
procedure division.
display "ClassLibraryCOBOL.Class1 Constructor()"
goback.
end method NEW.
method-id. NEW.
procedure division using aStr as String.
display "ClassLibraryCOBOL.Class1 Constructor(String)"
goback.
end method NEW.
method-id. NEW.
procedure division using anInt32 as binary-long.
display "ClassLibraryCOBOL.Class1 Constructor(Int32)"
goback.
end method NEW.
method-id. NEW.
procedure division using anInt16 as binary-short.
display "ClassLibraryCOBOL.Class1 Constructor(Int16)"
goback.
end method NEW.
method-id. NEW.
procedure division using anArray as type "System.Array".
display "ClassLibraryCOBOL.Class1 Constructor(System.Array)"
goback.
end method NEW.
*> …
method-id. "InstanceMethod".
local-storage section.
procedure division.
goback.
end method "InstanceMethod".
end object.
end class Class1.
For information on how you can define data types, read the topic COBOL Type Compatibility in the General Reference section of the Help of Net Express with .NET.