Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

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

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();
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...