值结构未在 WinRT 中初始化
value struct not initialized in WinRT
无论出于何种原因,Windows 运行时组件中定义的 value struct
的初始化值在应用程序 (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
}
}
请注意 flag1
应该是 True
而不是 False
。为什么? !
编辑:
正如@HansPassant 所建议的那样,为此创建一张票:https://connect.microsoft.com/VisualStudio/feedback/details/2702659
如果你也觉得这是个问题。请帮忙投票。
在 Microsoft connect https://connect.microsoft.com/VisualStudio/feedback/details/2702659
上发布问题后,我收到了来自 Microsoft VC++ 团队的电子邮件更新
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.
无论出于何种原因,Windows 运行时组件中定义的 value struct
的初始化值在应用程序 (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
}
}
请注意 flag1
应该是 True
而不是 False
。为什么? !
编辑: 正如@HansPassant 所建议的那样,为此创建一张票:https://connect.microsoft.com/VisualStudio/feedback/details/2702659 如果你也觉得这是个问题。请帮忙投票。
在 Microsoft connect https://connect.microsoft.com/VisualStudio/feedback/details/2702659
上发布问题后,我收到了来自 Microsoft VC++ 团队的电子邮件更新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.