0

Hello and please forgive the noob question.

I can for example EXPLICITLY define a variable using 'var' to be, for example, a DOUBLE type:

var num = 5d;

I know I know, I'm really obfuscating the fact that 'var' implies implicit! But really feel that there is an explicitness in defining the variable with the 'd', because as you are most likely aware, without the 'd', you are leaving it up to the compiler, hence to me a more implicit initialization.

This instead will define an Int32, and really, as you didn't make a choice (or maybe you were really smart and knew what the default would be - but the default might change in the future so be careful!),

var num = 5;

To my noob question however... Am trying to find a chart showing me all the available initializations.... But alas, I've forgotten "what" this type of initialization shorthand is called... :(

thank you!

Bill Roberts
  • 1,127
  • 18
  • 30
  • Required reading: [C# 3.0 is still statically typed, honest!](http://blogs.msdn.com/b/ericlippert/archive/2005/09/27/c-3-0-is-still-statically-typed-honest.aspx) – Sergey Kalinichenko Jul 12 '13 at 21:52
  • 1
    It's not `Int32` because of `X86` but because of the size of the integer literal. If it would not fit into `Int32` it would be an `Int64` implicitely. – Tim Schmelter Jul 12 '13 at 21:53
  • Thank you - actually built an x64 app to check after my original post and sure enough, it resolved to Int32. – Bill Roberts Jul 13 '13 at 02:03
  • dasblinkenlight - thx also for the comment - yeah understood that even using var, code is still strongly typed - I read two books on LINQ thus far. My point is when assigning a literal using var, the compile makes assumption... But by using a SUFFIX, it's like I'm doing an Explicit Implicit initialization :) – Bill Roberts Jul 13 '13 at 02:31

1 Answers1

1

If I understand you correctly, you are searching something like this: http://www.dotnetperls.com/suffix

Suffix type: unsigned int
Character:   U
Example:     uint x = 100U;

Suffix type: long
Character:   L
Example:     long x = 100L;

Suffix type: unsigned long
Character:   UL
Example:     ulong x = 100UL;

Suffix type: float
Character:   F
Example:     float x = 100F;

Suffix type: double
Character:   D
Example:     double x = 100D;

Suffix type: decimal
Character:   M
Example:     decimal x = 100M;

Of course you can also use lower case letters.

Kevin Brechbühl
  • 4,717
  • 3
  • 24
  • 47
  • lol - i was going to use the work "suffix" in place of "shorthand" but punted cuz it seemed so noob'ish :) Thanks for clarifying this issue for me! – Bill Roberts Jul 12 '13 at 23:36