Monday, July 18, 2005

Please, Let Me Keep My Unassigned Variables

If you compile code in C# that contains uninitialized variables, you will receive a compilation error in VS. C# imposes definite assignment, which requires that all variables be assigned before they are used (from Programming C#). I typically resolve this by assigning my object vars to null or, in the case of primitives, something like int.MaxValue or -1.

No comments: