2

When I do

1.toSting()

I get an error, but

// javascript
var a = 1; 

// or c#
int a = 1
a.toString()

works. Why is it that when a number gets assigned to a variable, it get some special functions?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3912349
  • 163
  • 1
  • 8

1 Answers1

7

The . is interpreted as you want a decimal/floating-point literal, not invoking a member.

You can do this in JavaScript

// Option 1
(1).toString();
// Option 2
1.0.toString();
// Option 3
1..toString();

In C#, it appears your only option is (1).ToString(), but the lexer might be smart enough not to need them.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445