Useful, but Overlooked C# Features
-
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
I had a strong dislike for C# var at first. I had a c++ background, and then worked in VB6. VAR was evil and had terrible side effects. However, in C#, even though it is 'var', it is strongly typed. So all the evil of VB6 is gone really. It does help the code look neater too. I have been assimilated.
-
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013- must identify as something other than human OR really dislike people who identify as something other than human.
-
What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013- The second amendment.
Wrong is evil and must be defeated. - Jeff Ello
-
What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
- The second amendment.
Wrong is evil and must be defeated. - Jeff Ello
The 2nd Amendment guarantees that you'll be able to defend your right to use 0-indexed lists.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
David A. Gray wrote:
Before I mark the project as completed, the
var
will almost certainly morph into something a lot more explicit.Hover your mouse over it, and it will tell you how it is resolved. Use that and be specific.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
- must identify as something other than human OR really dislike people who identify as something other than human.
I'd love to have a conversation with an intelligent member of another species. Come to think of it, I wouldn't mind a conversation with an intelligent member of my species - if I could find one... :-\
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
The 2nd Amendment guarantees that you'll be able to defend your right to use 0-indexed lists.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013:thumbsup:
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike
var
on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined avar
because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, thevar
will almost certainly morph into something a lot more explicit.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var". Or a case statement.
-
I had a strong dislike for C# var at first. I had a c++ background, and then worked in VB6. VAR was evil and had terrible side effects. However, in C#, even though it is 'var', it is strongly typed. So all the evil of VB6 is gone really. It does help the code look neater too. I have been assimilated.
-
David A. Gray wrote:
Before I mark the project as completed, the
var
will almost certainly morph into something a lot more explicit.Hover your mouse over it, and it will tell you how it is resolved. Use that and be specific.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Quote:
Hover your mouse over it, and it will tell you how it is resolved.
Absolutely! That's what I meant about it morphing into something more specific. Though the var type isn't technically "loosely typed," its type is formally undocumented. To my way of thinking, that is enough to qualify it as a code smell.
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var". Or a case statement.
Quote:
I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var
Nor will you see a
var
type in the locals and watch windows of the debugger.Quote:
Or a case statement.
The same holds true for C and C++. Moreover, in all three programming languages,
for
is actually three statements, each implemented as one or two machine instructions.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting