Question:

No Public Variables in C# so.....?

by  |  earlier

0 LIKES UnLike

Let me start off by saying that I am used to procedural coding, and I haven't quite grasped all of OOP. I have an assignment that I am having issues with. I need to create a random number (preferably when the form loads), then have the user continue to guess until they have gotten the correct answer, while the program keeps track of the number of tries.

So my problem is with the random number. I need to create a number in Form_Load, but how do I pass that number over to a btn_click procedure so I can check the guess against the random number?

 Tags:

   Report

1 ANSWERS


  1. There are public variables. That would be a global in the class. You probably have a class called Form1 or something within the namespace of your program. Why not just declare the variable at the beginning of the class?

    So like

    ...

    public partial class Form1: Form {

        int random_number = 0;

        public Form1() {

    ...

    that way it can be accessed from any method without having to pass it, eh?

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions