For whatever reason, the initialized value of a value struct
defined in Windows Runtime Component is ignored in the app (C#).
CX/C++:
namespace RuntimeComponent1
{
public value struct Foo {
bool flag1 = true;
bool flag2 = false;
};
}
C#
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
var settings = new RuntimeComponent1.Foo();
Debug.WriteLine(settings.flag1); // Output: False
Debug.WriteLine(settings.flag2); // Output: False
}
}
Notice that flag1
should be True
but instead it is False
. Why? !
Edit: As suggested by @HansPassant, create a ticket for this: https://connect.microsoft.com/VisualStudio/feedback/details/2702659 If you also think this is a problem. Please help up voting it.
I have got an email update from Microsoft VC++ team after posting the issue on Microsoft connect https://connect.microsoft.com/VisualStudio/feedback/details/2702659
Thank you for reporting this issue. The next release of the Visual C++ Compiler Toolset will issue an error when a member of a value class has a default member initializer.