how to return values from one class to another?
I'm making a program that has three classes:
- Output class receives data from other two classes, writes to two new strings, combines with special formatting to another string and outputs it
- AidaF class has a method that returns a value(a string) every second
- GmailF class has a method that returns a value(a string) every minute or so
so i tired using return string;
to return the data from classes 2 and 3 to the first class but that just returns the value to the current class, not to the first class.
Here is this code I'm working on, slimmed down a lot though. but basics are there.
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;
...
}
}
}
You need to call the exposed static methods from the calling class in order to get this to work, so for example your main would look more like this:
public static void Main() {
Console.WriteLine(GmailF.CheckMail() + AidaF.OnTimedEvent());
}
I'm just guessing that CheckMail and OnTimedEvent are the strings you are trying to return. Both CheckMail and OnTimedEvent have to be public static strings for the above to work.
精彩评论