|
Delphi |
|
Variables must be defined before using in special var blocks:
var
i: Integer;
d: Double;
This block can be both global defined the unit's interface or implementation part and local declared within the function or procedure:
procedure Dummy;
var
// this is local variable
i: Integer;
begin
for i:=0 to 10 do // some code here
end;
Global variables can be initialized by some default value:
var
Start: Integer = 99;
URL: string = 'http://www.greatis.com';
Delphi compiler fills all the global variables by zero values, so you don't need to initialize your variables when you need nil pointers, empty strings, zero in integers and doubles, etc.
var
// redundant code:
Start: Integer = 0;
URL: string = '';
Ptr: Pointer = nil;
var
// write it instead:
Start: Integer;
URL: string;
Ptr: Pointer;
Variables can be grouped when declaring several variables of one type:
var
StartValue, EndValue: Integer;
|
|
C# |
|
Variables can be declared any where in block before using its.
Variables can be initialized in declaration and must be initialized before using it.
Uninitialized variable have null default value.
There are no global variables in C#.
void Foo()
{
int i = 1; // declaration and initialization
int j;
j = i + 1; // ok initialization before using
int k;
j = k + 1; // error using variables before initializing
}
|
|
There are no global variables. |
|
|
|
Variable can be declarated in any code block immediately before using.
|
|
|
|
Do not forget, that null is not nil or zero value. Null is indicated unitilized variable that cannot be used before assigning some value. |
|
|
|
|
|
|
|
|
|
|
|