The literal for real number is default to double.
Therefore you have to add F
suffix when initializing a float
type variable.
Otherwise the C# compiler will generate error message.
using System;
class Program
{
static void Main(string[] args)
{
float f = 1.1;
Console.WriteLine(f);
}
}
The code above generates the following error message:
C:\g>csc Program.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(7,19): error CS0664: Literal of type double cannot be implicitly
converted to type 'float'; use an 'F' suffix to create a literal of this type
The same rule applies to decimal type literal.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |