Forum
ยป
c# brahs please help me
- Results 1 to 8 of 8
-
Page 1 of 1
Thread: c# brahs please help me
10-22-2020, 07:18 AM
-
#1
- darkeminence
- Registered User
-
- darkeminence
- Registered User
- Join Date: May 2007
- Age: 37
- Posts: 2,760
- Rep Power: 2174
-
-
c# brahs please help me
Ok I'm an utter noob in c#. Could anyone tell me why the variable in the content of the label doesn't get updated when I try to increment it in the method?
https://www.codepile.net/pile/yMdW2j8W
So here's what I'm thinking is happening: I declare the variable globally. Next, the event handler Window_Loaded put the text in the label, together with the value 0 of the int. Then when I try to click the button, it should increment the value of the variable in the label with 1. Why is this not happening brahs?
https://www.codepile.net/pile/yMdW2j8W
So here's what I'm thinking is happening: I declare the variable globally. Next, the event handler Window_Loaded put the text in the label, together with the value 0 of the int. Then when I try to click the button, it should increment the value of the variable in the label with 1. Why is this not happening brahs?
10-22-2020, 07:35 AM
-
#2
10-22-2020, 07:45 AM
-
#3
10-22-2020, 07:51 AM
-
#4
- Lucas5814
- Registered User
-
- Lucas5814
- Registered User
- Join Date: Apr 2020
- Age: 56
- Posts: 5,030
- Rep Power: 30809
-
-
I'm not a C# developer, but I work a lot with visual basic.
I'm guessing here: should you include some code to refresh the window? Is the count being set to 0 everytime the window updates/refreshes after a click?
My guess is, everytime you click, count is adding one, but the window is refreshing, and the first declaration is "count = 0", so it's just always going to be 0.
Again, I'm not a C# developer, so I don't know how this window stuff works.
I'm guessing here: should you include some code to refresh the window? Is the count being set to 0 everytime the window updates/refreshes after a click?
My guess is, everytime you click, count is adding one, but the window is refreshing, and the first declaration is "count = 0", so it's just always going to be 0.
Again, I'm not a C# developer, so I don't know how this window stuff works.
10-22-2020, 07:57 AM
-
#5
- darkeminence
- Registered User
-
- darkeminence
- Registered User
- Join Date: May 2007
- Age: 37
- Posts: 2,760
- Rep Power: 2174
-
-
Originally Posted By dcbone30⏩
Well I have to, since it's used in those 2 methods, don't I? If it were used in one method, I could declare it locally.
10-22-2020, 09:22 AM
-
#6
- darkeminence
- Registered User
-
- darkeminence
- Registered User
- Join Date: May 2007
- Age: 37
- Posts: 2,760
- Rep Power: 2174
-
-
Originally Posted By darkeminence⏩
bumpWell I have to, since it's used in those 2 methods, don't I? If it were used in one method, I could declare it locally.
10-22-2020, 09:37 AM
-
#7
- NiceGuy901
- Registered User
-
- NiceGuy901
- Registered User
- Join Date: Apr 2014
- Age: 35
- Posts: 540
- Rep Power: 2473
-
-
try this
Code:public partial class MainWindow : Window
{
public int count = 0;
private void btnMakeReservation_Click(object sender, RoutedEventArgs e)
{
this.count += 1;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lblLabel.Content = $"Let's count: {count}";
}
}
Code:public partial class MainWindow : Window
{
public int count = 0;
private void btnMakeReservation_Click(object sender, RoutedEventArgs e)
{
this.count += 1;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lblLabel.Content = $"Let's count: {count}";
}
}
10-22-2020, 09:48 AM
-
#8
- darkeminence
- Registered User
-
- darkeminence
- Registered User
- Join Date: May 2007
- Age: 37
- Posts: 2,760
- Rep Power: 2174
-
-
Originally Posted By NiceGuy901⏩
Doesn't work... Don't get it.try this
Code:public partial class MainWindow : Window
{
public int count = 0;
private void btnMakeReservation_Click(object sender, RoutedEventArgs e)
{
this.count += 1;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lblLabel.Content = $"Let's count: {count}";
}
}
Code:public partial class MainWindow : Window
{
public int count = 0;
private void btnMakeReservation_Click(object sender, RoutedEventArgs e)
{
this.count += 1;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lblLabel.Content = $"Let's count: {count}";
}
}
Bookmarks
-
- Digg
-
- del.icio.us
-

- StumbleUpon
-
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts