Skip to main content

How would you convert this to use anonymous methods using visual cobol for visual studio 2017?  I am more interested in the delegates and the use of the linq join extension.  The property's I can get and convert.  I cannot figure out how to work the join expression using delegates for visual cobol .net.

List<State> states = new List<State>()
            {
                new State {SID = 1, SName = "Telangana", SCode = " 91", SAbbrevation = "TG"},
                new State {SID = 2, SName = "Texas", SCode = "512", SAbbrevation = "TS"},
            };

            List<Country> coutries = new List<Country>()
            {
                new Country {CID = 1, CName = "India", CAbbrevation = "IND"},
                new Country {CID = 2, CName = "US of America", CAbbrevation = "USA"},
            };

            var res = coutries.Join(states,
                delegate(Country a) { return a.CID; },
                delegate(State b) { return b.SID; },
                delegate(Country a, State b) { return new {a.CName, b.SName}; }).ToList();

        }

        public class State
        {
            public int SID { get; set; }
            public string SName { get; set; }
            public string SCode { get; set; }
            public string SAbbrevation { get; set; }
        }

        public class Country
        {
            public int CID { get; set; }
            public string CName { get; set; }
            public string CAbbrevation { get; set; }
        }

How would you convert this to use anonymous methods using visual cobol for visual studio 2017?  I am more interested in the delegates and the use of the linq join extension.  The property's I can get and convert.  I cannot figure out how to work the join expression using delegates for visual cobol .net.

List<State> states = new List<State>()
            {
                new State {SID = 1, SName = "Telangana", SCode = " 91", SAbbrevation = "TG"},
                new State {SID = 2, SName = "Texas", SCode = "512", SAbbrevation = "TS"},
            };

            List<Country> coutries = new List<Country>()
            {
                new Country {CID = 1, CName = "India", CAbbrevation = "IND"},
                new Country {CID = 2, CName = "US of America", CAbbrevation = "USA"},
            };

            var res = coutries.Join(states,
                delegate(Country a) { return a.CID; },
                delegate(State b) { return b.SID; },
                delegate(Country a, State b) { return new {a.CName, b.SName}; }).ToList();

        }

        public class State
        {
            public int SID { get; set; }
            public string SName { get; set; }
            public string SCode { get; set; }
            public string SAbbrevation { get; set; }
        }

        public class Country
        {
            public int CID { get; set; }
            public string CName { get; set; }
            public string CAbbrevation { get; set; }
        }

The anonymous method syntax in Visual COBOL is very similar to C#. So in the case of:

var res = coutries.Join(states,
delegate(Country a) { return a.CID; },
delegate(State b) { return b.SID; },
delegate(Country a, State b) { return new {a.CName, b.SName}; }).ToList();

...somethind like:

declare res = coutries::Join(states,
delegate(Country a) returning ret as binary-long
set ret to a::CID
end-delegate
...
I'm not in a position to try this out right now, but that should be the general idea...

How would you convert this to use anonymous methods using visual cobol for visual studio 2017?  I am more interested in the delegates and the use of the linq join extension.  The property's I can get and convert.  I cannot figure out how to work the join expression using delegates for visual cobol .net.

List<State> states = new List<State>()
            {
                new State {SID = 1, SName = "Telangana", SCode = " 91", SAbbrevation = "TG"},
                new State {SID = 2, SName = "Texas", SCode = "512", SAbbrevation = "TS"},
            };

            List<Country> coutries = new List<Country>()
            {
                new Country {CID = 1, CName = "India", CAbbrevation = "IND"},
                new Country {CID = 2, CName = "US of America", CAbbrevation = "USA"},
            };

            var res = coutries.Join(states,
                delegate(Country a) { return a.CID; },
                delegate(State b) { return b.SID; },
                delegate(Country a, State b) { return new {a.CName, b.SName}; }).ToList();

        }

        public class State
        {
            public int SID { get; set; }
            public string SName { get; set; }
            public string SCode { get; set; }
            public string SAbbrevation { get; set; }
        }

        public class Country
        {
            public int CID { get; set; }
            public string CName { get; set; }
            public string CAbbrevation { get; set; }
        }

I figured it out if anyone would like to comment. There may be a better way but this is what I have thus far. I created another class to hold the combined list. I am calling it TO_ListJoin. It has all of the same properties as the States and Country's classes

declare res = countries::Join(states,
delegate(a as type TO_Country) returning x as binary-long
set x = a::CID
end-delegate,

delegate(b as type TO_State) returning y as binary-long
set y = b::SID
end-delegate,

delegate(c as type TO_Country, d as type TO_State) returning newlists as type TO_ListJoin
set newlists = new type TO_ListJoin
set newlists::CName = c::CName
set newlists::SName = d::SName
end-delegate
)


I could not figure out how to return a generic list and I thought mapping to class objects would be more efficient. Again, any comments would be appreciated.


How would you convert this to use anonymous methods using visual cobol for visual studio 2017?  I am more interested in the delegates and the use of the linq join extension.  The property's I can get and convert.  I cannot figure out how to work the join expression using delegates for visual cobol .net.

List<State> states = new List<State>()
            {
                new State {SID = 1, SName = "Telangana", SCode = " 91", SAbbrevation = "TG"},
                new State {SID = 2, SName = "Texas", SCode = "512", SAbbrevation = "TS"},
            };

            List<Country> coutries = new List<Country>()
            {
                new Country {CID = 1, CName = "India", CAbbrevation = "IND"},
                new Country {CID = 2, CName = "US of America", CAbbrevation = "USA"},
            };

            var res = coutries.Join(states,
                delegate(Country a) { return a.CID; },
                delegate(State b) { return b.SID; },
                delegate(Country a, State b) { return new {a.CName, b.SName}; }).ToList();

        }

        public class State
        {
            public int SID { get; set; }
            public string SName { get; set; }
            public string SCode { get; set; }
            public string SAbbrevation { get; set; }
        }

        public class Country
        {
            public int CID { get; set; }
            public string CName { get; set; }
            public string CAbbrevation { get; set; }
        }

I figured it out if anyone would like to comment. There may be a better way but this is what I have thus far. I created another class to hold the combined list. I am calling it TO_ListJoin. It has all of the same properties as the States and Country's classes

declare res = countries::Join(states,
delegate(a as type TO_Country) returning x as binary-long
set x = a::CID
end-delegate,

delegate(b as type TO_State) returning y as binary-long
set y = b::SID
end-delegate,

delegate(c as type TO_Country, d as type TO_State) returning newlists as type TO_ListJoin
set newlists = new type TO_ListJoin
set newlists::CName = c::CName
set newlists::SName = d::SName
end-delegate
)


I could not figure out how to return a generic list and I thought mapping to class objects would be more efficient. Again, any comments would be appreciated.