Hi
I'm designing a code where one can guess the Magic Number.
In my code I have this part here where I declared the randomNumber after the class Form1. (the green mark below).
Can somebody tell me what's the name of this part here? Is it static variable? And what about the randomNumber under the InitializeComponent();?

Thanks

public partial class Form1 : Form   
{    
[B]private static int randomNumber;    
private const int rangeNumberMin = 1;    
private const int rangeNumberMax = 10;    [/B]

public Form1()    
{       
InitializeComponent();        
randomNumber = GenerateNumber(rangeNumberMin, rangeNumberMax);    
}    

private int GenerateNumber(int min,int max)    
{        
Random random = new Random();        
return random.Next(min, max);    
}

regards
C# NewBie

Magic code indeed.


>I'm designing a code where one can guess the Magic Number.
In my code I have this part here where I declared the randomNumber after the class Form1.

It's a constructor.

>Can somebody tell me what's the name of this part here? Is it static variable?

>And what about the randomNumber under the InitializeComponent();?

GenerateNumber method return an int value and it is assigned to a static field - randomNumber.

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.