troubleshooting Question

How to get a C# method to return multiple values

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
2 Comments1 Solution12 ViewsLast Modified:
I am trying to refine my C# code to return two values.
trxDateToProcess  is a datevalue and
payPeriodToProcess  is an integer

What would be the proper way to get this method to return both values? The second record in the text file has both values. Do I setup a class to do this?

        private void GetTrxDatePayPeriodToProcess()
            int rc = 0;
            string[] format = { "yyyyMMdd" };

            using (var tfp = new TextFieldParser(Model.importFilename))
                /* Set up the comma as the delimieters used in the file */
                tfp.Delimiters = new string[] { "," };

                /* True if data fields can be in double quotes */
                tfp.HasFieldsEnclosedInQuotes = true;

                /* This means this file is a delimted file and NOT fixed width */
                tfp.TextFieldType = FieldType.Delimited;

                /* Remove white spaces from beginning and ending of each field */
                tfp.TrimWhiteSpace = true;

                while (rc < 2)
                    var data = tfp.ReadFields();                                /* Read the payroll import file records to get the pay period*/

                    if (DateTime.TryParseExact(data[0], format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dateValue))
                        Model.trxDateToProcess = dateValue;                                                                                 /* Trx_Date */
                        Model.trxDateToProcess = Model.badDate;

                    Model.payPeriodToProcess = data[4];

                    rc += 1;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros