Difference between C++ and C# RRS feed

  • Question

  • Hi, please, could someone explain me why the same WinRT type doesn't have the same representation between C++ and C# ?

    I guess the C# struct is a kind of wrapper over the WinRT type but why the C# properties are of type Double while the underlyng native fields are of type Float ?

    // c++/cx component method :

    void Graphics::DoSomething( Windows::Foundation::Rect r, Windows::Foundation::Point p );

    // c++ client code.

    Windows::Foundation::Rect r;
    r.Width = 1.0; // Width is a field of type Float.

    Windows::Foundation::Point p;
    p.X = 1.0; // X is a field of type Float.

    m_gfx->DoSomething( r, p );

    // c# client code.

    Windows.Foundation.Rect r;
    r.Width = 1.0; // Width is a property of type Double.

    Windows.Foundation.Point p;
    p.X = 1.0; // X is a property of type Double.

    m_gfx.DoSomething( r, p );

    Sunday, April 22, 2012 9:24 AM

All replies

  • Hello,

    You can check the document

    In the Fields section, you can find that:
    Width | width 
    Number [JavaScript] | System.Single [.NET] | float32 [C++]
    The width of the rectangle.

    The width in C# is Single and in C++ is float32.

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 23, 2012 6:38 AM
  • The documentation say "If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), then Rect has non-data members available, and its data members are exposed as read-write properties".

    Why the .NET properties returns Double instead of Single ?

    In c# we get this strange behaviour :

    double original = Double.MaxValue;
    Point p;
    p.X = original;
    double copy = p.X;

    if ( original != copy )
        throw new Exception( ); // !!!

    Monday, April 23, 2012 7:43 AM
  • I'm curious about the same thing and it is strange that there's no answer.

    My guess is: it only because of some body's personal opinion rather than technical reasons.

    WinRT is native code and is written by native developers, who care about performance and memory more. So they tend to use float.

    WPF used double for everything. And .NET for Metro style tries to be consistent with WPF/Silverlight.

    Tuesday, May 29, 2012 6:32 AM