0

So I was looking at the C# Documentation and I didn't see this in the example list though I know it works.

What is it called when you cast by putting a letter after the number.

var longValue = 100L;

According to the documentation it's not covered under implicit or explicit casting.

Is there a name for it?

I'm not asking how to do it. I am asking specifically what is it called. Please don't mark it as a duplicate unless you link something that has a name in it.

DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • yes duplicate, and see https://blogs.msdn.microsoft.com/csharpfaq/2004/03/12/how-do-i-tell-c-what-kind-of-literal-number-i-want/ – Bruno Mar 14 '16 at 13:36
  • 1
    It's not on that documentation page because it's not a cast or conversion. – D Stanley Mar 14 '16 at 13:37
  • 2
    It is not a cast. It's not an `int` that is converted to a `long`. It's a `long`. – Dennis_E Mar 14 '16 at 13:37
  • 2
    The name is in the dupe title btw. C# short/long/int **literal format**, – Pierre-Luc Pineault Mar 14 '16 at 13:38
  • 1
    @AnthonyRussell It's a `long` literal. That's the name for it. – D Stanley Mar 14 '16 at 13:38
  • 4
    Numeric suffix: http://www.dotnetperls.com/suffix – Idos Mar 14 '16 at 13:39
  • @AnthonyRussell: C# doesn't infer a 32bit int from `100L` any more than it infers one from `"100"`. Different value types have different literal notations, that's all. – David Mar 14 '16 at 13:40
  • 1
    @AnthonyRussell THe `L` tells C# that you want a `long`. And since you use `var` the compiler implicitly types `longValue` to `long`. If you had used `int longValue = 100L`, _then_ there would be a conversion attempt to `int`. – D Stanley Mar 14 '16 at 13:41
  • 1
    This includes no casting. In c# it is part of the integer literal within the spec. https://msdn.microsoft.com/en-us/library/aa664674(v=vs.71).aspx – Matthew Whited Mar 14 '16 at 13:42
  • @AnthonyRussell: And a number without quotes will be considered a 32bit int if you don't specify that it's a string. What's your point? – David Mar 14 '16 at 13:42
  • 3
    @AnthonyRussell It looks to me you answered your own question: you say 100L to tell C# you mean to say `long` instead of `int`. – Dennis_E Mar 14 '16 at 13:42
  • 1
    I love that he asks for the correct terminology then gets the question closed as duplicate/downvoted because a question about literals already exists. It clearly isn't the same question and I'm fairly sure asking basic things isn't disallowed. – Kelly Robins Jul 17 '16 at 21:49
  • @KellyGendron that's life... Their couple downvotes ain't hurting my feelings lol. – DotNetRussell Jul 17 '16 at 23:09
  • @AnthonyRussell Haahaa - SO downvotes are serious business! Have been on this site for a while and I guess the over-eagerness to close new questions is a huge pet peeve of mine. Duplicates especially as people don't take the time to understand the question - just react if they see similar keywords. I understand the frustration with dupes it has gone too far in the other directions and makes the site less useful as a resource. I don't ask q's often but frequently search and find a relevant question closed as dupe (with no answers) and linked to a subtly non-relevant question - is frustrating. – Kelly Robins Jul 18 '16 at 00:04
  • I actually prefer people post duplicate questions as long as they are marked duplicate and linked to the answers. The reason being is that there will be more pages with new was of asking the same questions indexed on Google linked to the right answer. – DotNetRussell Jul 18 '16 at 00:10

1 Answers1

1

This specify literal type. See for integer literals.

BWA
  • 5,672
  • 7
  • 34
  • 45