Every day, I work with both Javascript and C#. One thing that I often have to take into consideration when working with Javascript is hoisting. However, it seems that C# does not implement hoisting (as far as I know), and I can't seem to understand why. Is it a deliberate design choice or is it more of a security or language constraint that applies to statically typed languages?
Just to clarify, I'm not saying that I want hoisting to exist in C#. I simply want to comprehend the reasons behind its absence.
EDIT: The issue came to my attention when I declared a variable after a LINQ query, but the LINQ query was deferred until after the variable declaration.
var results = From c In db.LoanPricingNoFee Where c.LoanTerm == LoanTerm
&& c.LoanAdvance <= UpperLimit Select c
Order By c.LoanInstalment Ascending;
Int LoanTerm = 12;
This code throws an error, while:
int LoanTerm = 12;
var results = From c In db.LoanPricingNoFee Where c.LoanTerm == LoanTerm
&& c.LoanAdvance <= UpperLimit Select c
Order By c.LoanInstalment Ascending;
Does not.