33 Replies - 9432 Views - Last Post: 14 November 2012 - 06:46 PM
#16
Re: To 'var' or not to 'var'?
Posted 07 February 2012 - 07:25 AM
Again, I use it pretty much any time I can, and it works for me.
#17
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 03:39 AM
var amt = 2.13; var num = 3.15;
How would I know by reading the code which is a double and which is a decimal?
#18
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 04:52 AM
#19
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 06:13 AM
And that's true whether or not I'm using type inference.

So, don't call me lazy because I don't conform to your particular style guide, especially with an example that's just plain wrong. Personally, I think explicitly specifying a type is redundant, because everything you need to know is on the right hand side of the equals operator.
#20
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 06:52 AM
namespace HelloWorld
static class Program
public static void Main()
var x = 10.5
var y = 11.5
Console.ReadKey()
C# looks so much better with F# indenting rules.
#21
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 07:06 AM
#22
Re: To 'var' or not to 'var'?
Posted 29 March 2012 - 09:28 PM
of course if you use variable names like
var i = 8;
var s = "a string";
then you're likely to have a hard time telling what's in your variables farther down in your code, but that's true whether you define it implicitly or explicitly.
I also don't really see how it's being lazy to use var if, as someone else said, when declaring a variable explicitly you usually only have to type the first three letters and hit enter to get it from intellisense anyway (paraphrased). Either way you're typing about the same amount of characters.
This post has been edited by Nakor: 29 March 2012 - 09:33 PM
#23
Re: To 'var' or not to 'var'?
Posted 08 April 2012 - 04:16 AM
#24
Re: To 'var' or not to 'var'?
Posted 08 April 2012 - 04:38 AM
#25
Re: To 'var' or not to 'var'?
Posted 08 April 2012 - 06:29 AM
I don't think I'll ever fully commit to a style.
#26
Re: To 'var' or not to 'var'?
Posted 08 April 2012 - 06:43 PM
AdamSpeight2008, on 08 April 2012 - 06:38 AM, said:
That, or F12 on the method, or even hover over the method to see its return type. Frankly, as long as the information is available, I don't care if it takes one second longer to get it, if it maintains a consistent, easily-refactorable style.
#27
Re: To 'var' or not to 'var'?
Posted 11 April 2012 - 04:40 AM
Momerath, on 08 April 2012 - 06:16 AM, said:
If you're naming your methods correctly you should still be able to tell what the type is from the name of the method because it's usually going to be something like
var cars = GetVolkswagons();
This post has been edited by Nakor: 11 April 2012 - 04:42 AM
#28
Re: To 'var' or not to 'var'?
Posted 27 April 2012 - 02:17 PM
Nakor, on 11 April 2012 - 04:40 AM, said:
var cars = GetVolkswagons();
Does that return Volkswagons, Cars, ICars, IVolkswagons, Vehicles, IVehicles, etc.?
As for using the IDE to tell you what type it is, not all code is presented to you inside an IDE.
And Microsoft says
Quote
#29
Re: To 'var' or not to 'var'?
Posted 20 October 2012 - 06:14 AM
#30
Re: To 'var' or not to 'var'?
Posted 23 October 2012 - 07:16 AM
Momerath, on 27 April 2012 - 09:17 PM, said:
Nakor, on 11 April 2012 - 04:40 AM, said:
var cars = GetVolkswagons();
Does that return Volkswagons, Cars, ICars, IVolkswagons, Vehicles, IVehicles, etc.?
As for using the IDE to tell you what type it is, not all code is presented to you inside an IDE.
And Microsoft says
Quote
Up vote this post at least 30 more times please
|
|

New Topic/Question
Reply



MultiQuote





|