what the need of using single and float keywords separately . when we have to use single in the real time scenario?

删除回忆录丶 提交于 2019-12-14 03:32:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!