问题
when i am working with single and float in c#, i am getting the same result for both, then why 2 separate keywords.
namespace WpfApplication1 {
/// /// Interaction logic for MainWindow.xaml ///
public partial class MainWindow : Window {
public MainWindow() {
// Console.WriteLine("correct1");
float a = 10.6f; Single b = 10.6f;
Console.WriteLine("correct"+(a/b));
InitializeComponent();
}
}
}
回答1:
float is an alias for single.
float C# - MSDN
(Remember that float is an alias for the System.Single type.)
回答2:
what the need of using single and float keywords separately . when we have to use single in the real time scenario?
The two keywords are interchangable.
float
is actually provided by the C# language, and is an alias for System.Single
. You can't use Single
by itself, as its not merely a keyword, but the System.Single
type. This requires a using System;
at the top of your file or fully qualifying it. float
, on the other hand, is a language provided keyword, and will work in any scenario, without bringing in the namespace.
This is also the case with int
/System.Int32
, double
/System.Double
, etc.
来源:https://stackoverflow.com/questions/16779192/what-the-need-of-using-single-and-float-keywords-separately-when-we-have-to-us