0

I'm making a program that has three classes:

  1. Output class receives data from other two classes, writes to two new strings, combines with special formatting to another string and outputs it
  2. AidaF class has a method that returns a value(a string) every second
  3. 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; ... } } } 
7
  • I don't really understand what you're asking, but you seem to want to treat classes as procedures/functions... they really are not, practically or semantically. :-P Commented Sep 9, 2011 at 23:17
  • i want to return values from classes 2 and 3 so that class 1 can do something with them. Commented Sep 9, 2011 at 23:21
  • Are you trying to re-invent the "observable collection" pattern? That is, a collection is normally thought of as something you "pull" information from, one thing at a time, like a list of customers. An observable collection pushes information at consumers that are interested in it. Commented Sep 9, 2011 at 23:23
  • 2
    Classes are not things that "return" values; classes represent kinds of things. A class "Newspaper" represents the class of all objects that are newspapers. Methods return values. Commented Sep 9, 2011 at 23:24
  • 1
    this is where i was advised: stackoverflow.com/questions/7314638/… Commented Sep 10, 2011 at 1:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.