|
Marc Clifton wrote: Maybe an int that's the imaginary part of an imaginary number?
in an imaginary planet, in an imaginary universe?
|
|
|
|
|
var number = 0;
var result = method();
Wake up! The Singularity is coming.
|
|
|
|
|
nmarcel wrote: var number = 0;
The type inferred there is specifically a 32 bit signed integer.
If we intended "number" to be an Int64 for example, we'd have to either default it to a value that's too large for a 32 bit int and reset it to 0 or just take the simple route and declare it explicitly as an Int64.
What is the actual benefit of "var" here? "int number = 0;" is both more readable (we can see what type of int it is without resorting to tool-tips) and we're explicitly telling the compiler what to do rather than hoping it infers our intended type.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
|
|
|
|
|
PeejayAdams wrote: If we intended "number" to be an Int64 for example, we'd have to either default it to a value that's too large for a 32 bit int and reset it to 0 or just take the simple route and declare it explicitly as an Int64.
Or you could use:
var number = 0L;
Not that I would use it, it's just another way.
Although I would probably use:
long number = 0;
|
|
|
|
|
Absolutely!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
PeejayAdams wrote: What is the actual benefit of "var" here?
There is none.
We would do int number = 0 or decimal number = 0 , but never var number = 0 .
|
|
|
|
|
C# is essenially C++ as far as BNF concerned
|
|
|
|
|
count = 0 In Rexx everything's a string until it needs to be otherwise.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
C/C# style
int count = 0;
“The palest ink is better than the best memory.” - Chinese Proverb
|
|
|
|
|
This.
".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
|
|
|
|
|
var is a very helpful typesafe way to more loosely declare your variables. I quite like it.
dynamic would be closer to something like a script's object variable.
either might apply to this quiz
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
A rather weird survey as Mike B. pointed out.
So let's get down to the heart of the matter: VAR IS EVIL.
I shall now adopt my flame-proof suit.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
|
|
|
|
|
the real war is the naming battleground. Lately a collegue coded this:
testHelper.add() I politly stayed silent...
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
var is not evil, when used correctly, but it is also a pointless and futile debate topic.
No flame wars on this one.
|
|
|
|
|
Awwww... *puts away the popcorn*
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I love "var". I use when writing a declaration for the first time and then see what the actual type is, using intellisense, and change it to that. It makes working out what some of the more obscure method calls actually return a lot easier.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Yes, I use it the same way - just hate to see it left in code.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
|
|
|
|
|
PeejayAdams wrote: So let's get down to the heart of the matter: VAR IS EVIL.
Agreed. I like my code to self document to some extent and var doesn't provide this feature.
|
|
|
|
|
int count .
var test = new Test() ;
That is how I and our shop does it and we are mostly C#.
|
|
|
|
|
i use var as consistently as possible, with the notable exception of how i for over collections
for(int ic=col.Count, i=0;i<ic;++i) {}
but that's mainly for expediency and to keep my count variable
to a narrow scope. i almost wish C# supported var there.
i just like consistency in that. *shrug*. I think it's easy
enough to tell what the variable is using modern tools such
that explicit declarations aren't that important, but that's
just my $0.02, YMMV
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I use foreach instead of for 99.9% of the time. That way I use var .
I only use for when I need access to the loop pointer/index in a particular way, etc.
|
|
|
|
|
you can use var with for, just not with the double initializer i use.
for(var i = ...
works
for(var ic = foo,i=
does not
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Ditto - This is how I use it.
|
|
|
|
|
C#
Thanks
Happy Coding
|
|
|
|