Skip to main content
Solved

Help to convert C#-Lambda-Command to .NET COBOL in Visual Cobol ?

  • February 13, 2026
  • 2 replies
  • 30 views

Kim Hoskin
Forum|alt.badge.img+2

Hi,

I am posting this question on behalf of a customer, to ensure it goes to the relevant forum and a place they they can see the post. Once I post this I'll share the link with the customer and ask to reply/comment here also.


They ask:
Does somebody know how to translate the following C#-Lambda-Command to Visual Cobol ?

Example (the second last line):

private void FlexGrid_Load(object sender, EventArgs e)
{
string conn = Util.GetConnectionString();
var ds = new DataSet();
string[] tables = "Customers, Orders".Split(',');
foreach (string tableName in tables)
{
Util.FillTable(ds, tableName, conn);
}
// Defining relation between master and detail grid
ds.Relations.Add("Customers_Orders",
ds.Tables["Customers"].Columns["CustomerID"],
ds.Tables["Orders"].Columns["CustomerID"]);
flexGrid.DataSource = ds;
flexGrid.DataMember = "Customers";
flexGrid.RowDetailProvider = (g, r) => new C1FlexGridRowDetail();
flexGrid.AreRowDetailsFrozen = false;
}
}

They have used the C# to COBOL convertor website but the code that is returned from that gives various compile errors.

For example, if taking an example from this Microsoft page:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions

C# example:

Func<int, int> square = x => x * x;
Console.WriteLine(square(5));
// Output:
//25

For that the C# to COBOL convertor gives:

    declare #square as type Func[binary-long, binary-long] =
      delegate (x)
        set return-value to x * x
      end-delegate
    invoke type Console::WriteLine(#square(5))
    *> Output:
    *> 25

Customer tries that:

declare #square as type Func[binary-long, binary-long] =
      delegate (x as binary-long)
        set return-value to x * x
      end-delegate

Get the compile message 'cannot implicitly convert anonymous method to type System.Func[binary-long, binary-long]'

I would like to ask if anyone can offer they guidance to help with this query.

Regards,
Kim

Best answer by Chris Glazier

Give this a try…

 declare #square as type Func[binary-long, binary-long] = 
delegate using x as binary-long returning myresult as binary-long
set myresult to x * x
end-delegate

display #square(5)

 

2 replies

Chris Glazier
Forum|alt.badge.img+3
  • Moderator
  • Answer
  • February 13, 2026

Give this a try…

 declare #square as type Func[binary-long, binary-long] = 
delegate using x as binary-long returning myresult as binary-long
set myresult to x * x
end-delegate

display #square(5)

 


Kim Hoskin
Forum|alt.badge.img+2
  • Author
  • Moderator
  • February 16, 2026

Give this a try…

 declare #square as type Func[binary-long, binary-long] = 
delegate using x as binary-long returning myresult as binary-long
set myresult to x * x
end-delegate

display #square(5)

 

Thank you for your help Chris.