谢谢 约翰解决方案 一号线上读到我注意到在foreach你打印整个列表? foreach (对象 item in commonMsgIdThreeBuses) { Console.WriteLine( item ); } 如果您正确加载列表中的数据,可能会出现问题。 为什么你没有看到你的信息有太多可能的原因:没有你的实际数据,我们甚至无法猜出它可能是哪一个。 所以,这取决于你! 首先要做的是获取有关正在发生的事情的信息。因此,在上面的代码的第一行放置一个断点,并在调试器中运行你的应用程序: List< string> commonMsgIdThreeBuses = new List< string>(); < / 字符串 > < / string > 当执行到达该行时,调试器将在执行之前停止,让您看看发生了什么。 单步执行程序(这意味着一次执行一行 - 工具栏上有一个按钮),在你做之前计算出应该发生的结果。你的期望发生了什么?如果是这样,请转到下一个。如果没有,为什么不呢? 请注意,您可以通过将鼠标悬停在变量上来找出变量包含的内容。以及通过Auto,Local和Watch窗格。 当你知道它到底在做什么时,你可以开始思考为什么 - 然后你就可以开始寻找对于这个问题。但我们不能为你做到这一点! 如果commonMsgIdThreeBuses正确填充,则以下代码应该有效。 foreach (对象项目 in commonMsgIdThreeBuses) { Console.WriteLine(item); } Hi,I am reading a excel file with 3 excel sheets and checking the rows of excel sheet for message IdIf the message Id is same in the 3 excel rows I am saving them into list stringI am using the following code doing it List<string> commonMsgIdThreeBuses = new List<string>(); if (lstDS.Count == 3) { List<string> timeStamp = new List<string>(); foreach (DataRow row in lstDS[2].Tables[0].Rows) { string fieldFromDB = row[1].ToString(); string FromDB = row[2].ToString(); foreach (DataRow row1 in lstDS[0].Tables[0].Rows) { string fieldFromDB1 = row1[1].ToString(); if (fieldFromDB == fieldFromDB1) { foreach (DataRow row2 in lstDS[1].Tables[0].Rows) { string fieldFromDB2 = row2[1].ToString(); if (fieldFromDB == fieldFromDB2) { commonMsgIdThreeBuses.Add(fieldFromDB); } } } } } } foreach (Object item in commonMsgIdThreeBuses) { Console.WriteLine(commonMsgIdThreeBuses); } Console.ReadKey();The problem is that I cannot see the message Ids on consoleCan anyone help me in solving thisThanksJohn 解决方案 Well on 1st read i noticed that in foreach u print whole list ?foreach (Object item in commonMsgIdThreeBuses) { Console.WriteLine(item); }Maybe that is problem if u load data in list correctly.There are far, far too many possible reasons why you don't see your message: and without your actual data we really can't even begin to guess which one it might be.So, it's up to you!The first thing to do is get information on exactly what is happening. So put a breakpoint on the first line in the above code, and run your app in the debugger:List<string> commonMsgIdThreeBuses = new List<string>();</string></string>When execution reaches that line, the debugger will stop before it executes it, and let you see what is going on.Single step through your program (which means to execute it a line at a time - there is a button on the toolbar for that) working out what should happen as a result before you do. Did what you expected happen? If so, move to the next. If not, why not?Note that you can find out what a variable contains by hovering the mouse over it. As well as via the Auto, Local and Watch panes.When you know what exactly it is doing, you can start thinking about why - and then you can start looking for the problem. But we can't do that for you!if commonMsgIdThreeBuses is filled properly then the following code should work.foreach (Object item in commonMsgIdThreeBuses) { Console.WriteLine(item); } 这篇关于无法在控制台上看到列表字符串数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-15 12:14