如何在Windows窗体应用程序中读取从form1到form2的日志文件的内容 [英] How can I read the contents of log file from form1 to form2 in Windows forms application
本文介绍了如何在Windows窗体应用程序中读取从form1到form2的日志文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下命令读取form1中日志文件的内容
Hi,
I am reading the contents of log file in form1 using the following command
private void ReadLogFile(string dataLogFile)
{
string[] fileContents = null;
fileContents = File.ReadAllLines(Properties.Settings.Default.LogFilePath + dataLogFile);
}
此功能不返回
现在我需要在form2中使用相同的字符串数组
任何人都可以建议我,我需要使用什么命令?
谢谢
John
This function returns nothing
Now I need to use the same string array in in form2
Can anyone suggest me, what command I need to use for this??
Thanks
John
推荐答案
将其更改为
change it to
public static string[] ReadLogFile(string dataLogFile)
{
string[] fileContents = null;
fileContents = File.ReadAllLines(Properties.Settings.Default.LogFilePath + dataLogFile);
return fileContents ;
}
现在这将返回数组中的日志文件行..
in Form2
你可以调用这个函数,比如
string [] fileContents = Form2.ReadLogFile(你的文件);
now this will return the log file lines in an array..
in Form2
you can call this function like
string[] fileContents = Form2.ReadLogFile("your file ");
你有几个选项:
- 使此方法返回字符串数组。
- 声明
fileContents
作为公共成员Form1
。- 声明
fileContents
作为的公共静态成员程序
class。- ...
You have several options:
- Make this method return the string array.
- Declare
fileContents
as public member ofForm1
.- Declare
fileContents
as public static member of yourProgram
class.- ...
添加字符串返回键入你的方法,
并返回你正在提取的对象,
最后调用此方法并将其等同于Form2中的数组
As
string Form2Array [] = YourMethodName();
Add An String Return Type To Your Method,
And Return The Object That You Are Fetching,
Finally Call This Method And Equate It To Array In Form2
As
string Form2Array[] = YourMethodName();
这篇关于如何在Windows窗体应用程序中读取从form1到form2的日志文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文