The Daily WTF
Astor works for a company that provides software for research surveys. Someone needed a method to return a single control object from a list of control objects, so they wrote this C# code:
private ResearchControl GetResearchControlFromListOfResearchControls(int theIndex, List<ResearchControl> researchControls) { var result = new ResearchControl(); result = researchControls[theIndex]; return result; }
Astor has a theory: “I can only guess the author was planning to return some default value in some case…”
I’m sorry, Astor, but you are mistaken. Honestly, if that were the case, I wouldn’t consider this much of a WTF at all, but here we have a subtle hint about deeper levels of ignorance, and it’s all encoded in that little var.
C# is strongly typed, but declaring the type for every variable is a pain, and in many cases, it’s redundant information. So C# lets you declare a variable with var, which does type
To read the full article click on the 'post' link at the top.