Passing an Object when including a class

M

mmatchyn

Is there a way to pass an object when including a class?

For example...

namespace testclass
{
public System.Windows.Forms.TextBox textbox;
public class Write
{
public Write(string msg)
{
textbox.text = msg;
}
}
}

So when I call the following:
using testclass

I would like to pass in the textbox from the form. I don't want to
have to pass the textbox every time I call the write methode. Is
there a way I can set this up in the using or one line of code shortly
after but independant and outside of the write class?
 
M

Mattias Sjögren

namespace testclass
{
public System.Windows.Forms.TextBox textbox;

This won't even compile, since you can't have global fields in a
namespace. Move the field to a class, and add a constructor that will
initialize it.

So when I call the following:
using testclass

A using statement doesn't call anything, it simply saves you from
typing out the fully qualified name when using a type.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top