hi i need to use a variables from page to show in another page at text block in windows phone 7. i got a problem that the second page doesn’t declare the variables: here’s a part of my code:
public static class MainPage : PhoneApplicationPage
{
string result;//var i wanna use at the all application pages
string status;//var i wanna use at the all application pages
string userId;//var i wanna use at the all application pages
string msg;//var i wanna use at the all application pages
WebClient client;
// Constructor
public MainPage()
{
InitializeComponent();
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
}
///second page
public partial class info : PhoneApplicationPage
{
public info()
{
InitializeComponent();
textBlock1.Text = result.value();
}
}
but this code dosent work ny help??
Because your variables are private and their scope is limited to the
MainPageclass.If you want them to be public, you have to add the
publickeyword.Better: you should use properties instead:
Also, you can’t write a global variable. As C# is an object-oriented programming language, you’ll have to use an instance of your
MainPageclass to access to your properties:Another thing: you’re using variables/properties, not functions. So you can’t write
result.value();. Useresult.value;instead.I suggest you to have a look at this MSDN article about properties.