Variable declaration

In BI# you can declare local variables in every block of a program. This program example defines a local variable named number that is local to the function DeclareVariable. That is, it is only visible within the function:

void DeclareVariable()
{ 
	int number = 42; 
}

Blocks can be nested at an arbitrary depth, that is, you can add blocks to a function's main block:

void InitVariable()
{ 
	int number = 42;
	if (true) 
	{ 
		double x = 0.0; 
	} 
}

The program above defines a double variable named x in a block that belongs to the true branch of an if statement. The variable x is only visible within this block.

BI# does not allow the redefinition of variables, even if you declare the variables in separate blocks:

void Example(string name)
{ 
	int name = 0; // This is not allowed!
	double pi = 3.14;
	if (true)
	{ 
		double pi = 3; // This is not allowed! 
	}
}