我正在创建一个包含三个类的程序:
所以我厌倦了使用return string;
将类2和3中的数据返回到第一个类但是只返回当前类的值,而不是第一个类。
以下是我正在处理的这段代码,尽管如此还是很简单。但基础知识就在那里。
namespace Final
{
public class Output
{
public static void Main()
{
Console.WriteLine(gml + aida);
}
}
public class AidaF
{
private static System.Timers.Timer aTimer;
public static void AMain()
{
aTimer = new System.Timers.Timer(1000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 1000;
aTimer.Enabled = true;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
...
reader.ReadToFollowing("value");
aida.Append(reader.ReadElementContentAsString()).Append(",");
return aida;
...
}
}
public class GmaillF
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(200000);
gTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent1);
gTimer.Interval = 200000;
gTimer.Enabled = true;
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{
CheckMail();
}
public static string CheckMail()
{
...
gml.Append(reader.ReadElementContentAsString()).Append(",");
return gml;
...
}
}
}
答案 0 :(得分:1)
您需要从调用类调用公开的静态方法才能使其正常工作,例如,您的main看起来更像是这样:
public static void Main() {
Console.WriteLine(GmailF.CheckMail() + AidaF.OnTimedEvent());
}
我只是猜测CheckMail和OnTimedEvent是你想要返回的字符串。 CheckMail和OnTimedEvent都必须是公共静态字符串才能使上述工作。