Highlighted
Contributor.
Contributor.
583 views

Object Initializer

Jump to solution

How would you write the student.Add(new Student() {....} in .net cobol.  My attempt is

invoke student::Add(new Student() (new Student::ID

This is as far as I got before syntax errors.

SqlDataReader dr;
            try
            {
                conn.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    student.Add(new Student()
                    {
                        ID = dr.GetInt32(dr.GetOrdinal("ID")),
                        Name = dr.GetString(dr.GetOrdinal("Name")),
                        DateOfBirth = dr.GetDateTime(dr.GetOrdinal("DateOfBirth"))
                    });
                    
                }
                dr.Close();
            }
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Object Initializer

Jump to solution
It's difficult to be sure, as I don't have the whole program context but something like:
invoke student::Add(new Student(prop ID = dr::GetInt32(...)
prop Name = ...
prop DateOfBirth =...))
You can set properties for the new object like this from within a constructor expression, using keyword 'prop' or 'property'.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Object Initializer

Jump to solution
It's difficult to be sure, as I don't have the whole program context but something like:
invoke student::Add(new Student(prop ID = dr::GetInt32(...)
prop Name = ...
prop DateOfBirth =...))
You can set properties for the new object like this from within a constructor expression, using keyword 'prop' or 'property'.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.