Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

How to get a C# method to return multiple values

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 */
                    }
                    else
                    {
                        Model.trxDateToProcess = Model.badDate;
                    }

                    Model.payPeriodToProcess = data[4];

                    rc += 1;
                }
            }
        }
ASKER CERTIFIED SOLUTION
Avatar of Andrei Fomitchev
Andrei Fomitchev
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What Andrei suggested is what I was about to say, just return a data structure that contains both values.