Show/Hide Toolbars

XSharp

Use of unassigned local variable 'name'

 

The X# compiler does not allow the use of uninitialized variables. If the compiler detects the use of a variable that might not have been initialized, it generates compiler error XS0165. For more information, see Fields. Note that this error is generated when the compiler encounters a construct that might result in the use of an unassigned variable, even if your particular code does not. This avoids the necessity of overly-complex rules for definite assignment.

Example

 

The following sample generates XS0165:

 

 

// XS0165.prg  
 

 

 

Example

 

Compiler error XS0165 can occur in recursive delegate definitions. You can avoid the error by defining the delegate in two statements so that the variable is not used before it is initialized. The following example demonstrates the error and the resolution.