如何将构造函数的数据移动到datatable [英] How can I move the data of constructor to datatable

查看:119
本文介绍了如何将构造函数的数据移动到datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用构造函数使用以下代码保存日志文件所需的数据



现在,如何通过调用它将此方法的数据返回到main方法?



我尝试使用return,但它在这里不起作用



Hi,

I am using a constructor to save the required data of log file using the following code

Now, how can I return the data of this method to main method by calling it??

I tried using return, but it does not work here

private void ReadLogFile(string dataLogFile)
        {
            string[] fileContents = null;
            List<MsgIdTimeStampMap> CANMsgIdList = new List<MsgIdTimeStampMap>();
            
            try
            {
                // Open and read the entire Data Log File contents.
                fileContents = File.ReadAllLines(Properties.Settings.Default.LogFilePath + dataLogFile);
            }
            catch(Exception ex)
            {
                throw new Exception("The Input log file was not found or is not in correct format\nDetails: " + ex.Message);
            }

           

            if (fileContents == null) 
                throw new Exception("The Input log file was not found or is not in correct format");

            // Process each line of the Data Log File and filter out the CAN Msg Id's corresponding to each CAN Bus.
            for (int Index = 0; Index < fileContents.Length; Index++)
            {
                string CANMsgId = string.Empty;
                string timeStamp = string.Empty;
                string[] spaceSeperator = new string[] { " " };
                string[] lineWords = (fileContents[Index].Trim()).Split(spaceSeperator, StringSplitOptions.RemoveEmptyEntries);

                // If the number of words in a line is less than 3 then its not a valid entry.
                if (lineWords.Length < (Constants.CAN_MSGID_HEX_INDEX + 1)) 
                    continue;

                // If a CAN Msg Id is valid, it should end with 'x'. If it doesnot end with 'x',
                // then skip the entry and go to the next line of log file
                if (lineWords[Constants.CAN_MSGID_HEX_INDEX].EndsWith("x"))
                {
                    CANMsgId = lineWords[Constants.CAN_MSGID_HEX_INDEX].TrimEnd('x');
                     timeStamp = lineWords[Constants.CAN_TIMESTAMP_INDEX];
                }
                else
                    continue;

                // Check the format of the CAN Msg Id, whether Hex or not.
                if (Regex.IsMatch(CANMsgId, Constants.CAN_MSGID_HEX_FORMAT_REGREX))
                {
                    Buses CANBus = (Buses)Enum.Parse(typeof(Buses), (lineWords[Constants.CAN_BUSID_INDEX]));
                     CANMsgIdList.Add(new MsgIdTimeStampMap(CANBus, CANMsgId, timeStamp));
                }
            }
             
             
           
     }







谢谢

John




Thanks
John

推荐答案

我不知道你想要什么返回,但是,你确实意识到您的返回类型当前是 void ,对吧?这可能是你的 return 语句不起作用的原因。
I have no idea what you want to return, but, you do realize that your return type is currently void, right?? That's probably why your return statement didn't work.


这篇关于如何将构造函数的数据移动到datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆