Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...