0
public partial class MainWindow: Window {
    public static ABClient client;

    public MainWindow() {
        InitializeComponent();
        client=new ABClient();
        client.Connect();
    }
}

class B {
    public B() {
        client.Connect();  // The name 'client' does not exist in the current context
    }
}

Why do I get this compile error if client is public? I need to have one client which would be accessible from any other window or class. Please help with the solution.

0

1 Answer 1

4

You need to call it this way :

MainWindow.client.Connect(); 
1
  • 1
    Thanks, what a stupid mistake. That's because I used to learn on console apps.
    – Dork
    Commented Mar 2, 2013 at 19:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.