This is a requirement of the C# compiler, since it doesn't allow access to unassigned local variables, even though those variables may be value types that don't need to be explicitly initialized. The proper handling of this compiler requirement is to initialize all variables, which in some cases I find to be rather annoying.
Take the following VB.NET code for example:
Visual Basic:
Dim r As Rectangle
This will compile just fine, since the VB.NET compiler doesn't fuss about unassigned variables (which isn't always a good thing mind you). Note that both lines of code generate the exact same line of MSIL and the C# error message is produced during compilation (as mentioned above), not at runtime.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.