• 0

[C#] Help with classes


Question

I really need some help understanding something in C# and I'm not really sure where to look (I have no idea what to call it or anything).

Basically, I have two classes, lets call them class A and class B. I also have a form which class A and class B are both declared in.

I need both classes to be able to send messages to a debug console and other controls in the form.

Class A and class B will also use each others data at times, is there any way of centralising data without putting somewhere external (like a db/text file).

Any got any ideas how to do this? Sending messages to a debug console is the one that stumps me most.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

it's hard to say, but asking a few questions might help as it sounds like you need to restructure things..

what do class A and B actually do? can their be put into one class? can their functionality be put into the main?

from the rather sparse description you have given i would likely a new class to do your logging with static methods so you can call something like logThis("an item") throughout your code..

as for the holding data, this is easily doable again, with a with another class that you can store in a list, the contents of which you can get and set... but of course this data will only be available at runtime, and will be destroyed when the application closes... so you really do want to output somewhere if you plan on 'saving' it for later...

it is not too much hassle to output things to a file..

but i think you need to define / explain your requirements a bit more if i'm honest

Link to comment
Share on other sites

  • 0

Well for the first one, you could use events, where the event is declared in the classes as public, and then raised when the class its declared in does something passing the data you need in as an eventarg. The form handles the event to do whatever you need it to much in the same way that you have event handlers for double clicks and stuff. That means that when class a/b does something, it will run the event handler code in the form.

The second I'd go with BGMs method of doing things by using third class to hold the common data, and have a pointer (?) to that data in your instances of Class A and Class B

The debugging bit is as simple as using System.Diagnostics.Debug.Writeline("asdasdsa2");

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.