Click here to Skip to main content
15,890,399 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using the Black Box method in C# Pin
Brian_TheLion6-Mar-19 11:32
Brian_TheLion6-Mar-19 11:32 
Questionc#, winforms, moving the app to another monitor and updating the screen device name Pin
jkirkerx4-Mar-19 7:01
professionaljkirkerx4-Mar-19 7:01 
AnswerRe: c#, winforms, moving the app to another monitor and updating the screen device name Pin
jkirkerx4-Mar-19 7:15
professionaljkirkerx4-Mar-19 7:15 
GeneralHow to center a progress bar dialog across multiple monitors Pin
jkirkerx4-Mar-19 9:44
professionaljkirkerx4-Mar-19 9:44 
AnswerRe: c#, winforms, moving the app to another monitor and updating the screen device name Pin
Gerry Schmitz5-Mar-19 8:24
mveGerry Schmitz5-Mar-19 8:24 
GeneralRe: c#, winforms, moving the app to another monitor and updating the screen device name Pin
jkirkerx5-Mar-19 10:37
professionaljkirkerx5-Mar-19 10:37 
QuestionPlease tell me what is wrong with this simple C# program Pin
Brian_TheLion3-Mar-19 23:20
Brian_TheLion3-Mar-19 23:20 
AnswerRe: Please tell me what is wrong with this simple C# program Pin
OriginalGriff3-Mar-19 23:46
mveOriginalGriff3-Mar-19 23:46 
Clicker is declared inside the Form constructor:
public Form1()
    {
    InitializeComponent();
    int Clicker=0;
    }
Which means it is a local variable - it's scope is restricted to the set of curly brackets in which it is declared. When it goes out of scope (i.e. outside those curly brackets) it no longer exists, and the variable is destroyed (but not it's content - you'll find out about the difference later).

So you can't use it in your Click_Counter method even if it was in the same class - which it isn't - or would compile, which it wouldn't as it doesn't specify a return type. Only Constructors can be defined without a return type! And "Clicker" is not the same as "Checker"!

Move the Clicker definition to class level, so it's not inside any method, move the Click_Counter method inside the Form1 class, give it a return type, and get the names right:
namespace Click_Counter
    {
    public partial class Form1 : Form
        {
        private int Clicker=0;
        public Form1()
            {
            InitializeComponent();
            }
        
        public void button1_Click(object sender, EventArgs e)
            {
            ClickCounter();
            }
        
        public void ClickCounter()
            {
            Clicker++;
            ClickCounterBox.Text = "You clicked the button " + Clicker.ToString();
            }
        }
    }
I declared Clicker as private so it's only available inside the class - you only expose what you need to to the outside world!
I've also changed the name from Click_Counter to ClickCounter, as that's the standard naming convention: you don't use underscore in names except in special cases in C#
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Please tell me what is wrong with this simple C# program Pin
Brian_TheLion4-Mar-19 0:02
Brian_TheLion4-Mar-19 0:02 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
OriginalGriff4-Mar-19 0:05
mveOriginalGriff4-Mar-19 0:05 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
Brian_TheLion4-Mar-19 0:37
Brian_TheLion4-Mar-19 0:37 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
Richard MacCutchan4-Mar-19 0:41
mveRichard MacCutchan4-Mar-19 0:41 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
Richard MacCutchan4-Mar-19 0:43
mveRichard MacCutchan4-Mar-19 0:43 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
Brian_TheLion4-Mar-19 1:05
Brian_TheLion4-Mar-19 1:05 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
Brian_TheLion4-Mar-19 0:41
Brian_TheLion4-Mar-19 0:41 
GeneralRe: Please tell me what is wrong with this simple C# program Pin
OriginalGriff4-Mar-19 0:47
mveOriginalGriff4-Mar-19 0:47 
QuestionWhat is free alternative to microsoft bot framework? Pin
Nitin S3-Mar-19 21:14
professionalNitin S3-Mar-19 21:14 
AnswerRe: What is free alternative to microsoft bot framework? Pin
Richard MacCutchan3-Mar-19 21:46
mveRichard MacCutchan3-Mar-19 21:46 
AnswerRe: What is free alternative to microsoft bot framework? Pin
Eddy Vluggen4-Mar-19 0:36
professionalEddy Vluggen4-Mar-19 0:36 
QuestionC# Code converted from Java gives error using in Script Task in SSIS Pin
Member 141699203-Mar-19 18:42
Member 141699203-Mar-19 18:42 
AnswerRe: C# Code converted from Java gives error using in Script Task in SSIS Pin
OriginalGriff3-Mar-19 19:56
mveOriginalGriff3-Mar-19 19:56 
RantWhy is float to double conversion uniquely terrible? Pin
Eric Lynch3-Mar-19 2:21
Eric Lynch3-Mar-19 2:21 
GeneralRe: Why is float to double conversion uniquely terrible? Pin
Richard MacCutchan3-Mar-19 2:40
mveRichard MacCutchan3-Mar-19 2:40 
GeneralRe: Why is float to double conversion uniquely terrible? Pin
Eric Lynch3-Mar-19 4:24
Eric Lynch3-Mar-19 4:24 
GeneralRe: Why is float to double conversion uniquely terrible? Pin
Richard MacCutchan3-Mar-19 5:14
mveRichard MacCutchan3-Mar-19 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.