Hey there,

I want to start off by saying I am not here to "post and pick up." What I mean by "post and pick up" is that I need help with a homework assignment simply put, and am NOT here to have someone do my homework for me.

That said...

The assignment is quite a doozie for me, so I figured after exausting my texts and web references, I would ask for a little help. The assignment is to write an application that uses a struct (see below) and methods to get input as well as print to the screen. I am having trouble with variable scope, I have variables in one method and can't access them in another.

Code:

struct WeatherStation
{
        //Private variable declarations
        public string stationDesignation;
        public double stationTemp;
        public string stationContact;

        //This is where my methods were
}

Quite frankly I am not even sure I am placing the methods in the right place, maybe I am missing something really stupid and simple. Any help to set me off in the right direction would be exelent. For those who might have some good ideas, I can send more of the actual assignment or my code for context's sake.

Thanks,
Rich

Ok, when you declare a class or a struct and you don't use any access modifiers, unless you specify otherwise, they default to PRIVATE.

So your variable declarations above are actually public, not private. Whereas if you don't use the "public" access modifier on your methods they will be private.

struct MyStruct
{
    // These are Private
    String MyString;
    Int32 MyInt;

    // These are Public
    public String MyPublicString;
    public String GetMyString() { return MyString; }
}

public struct MyPublicStruct
{
    // These are Public
    String MyString;
    Int32 MyInt;
}

Hope this has allowed you to understand =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.