gpt4 book ai didi

c# - 值结构未在 WinRT 中初始化

转载 作者:行者123 更新时间:2023-11-30 17:37:57 25 4
gpt4 key购买 nike

无论出于何种原因,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 上发布问题后,我收到了来自 Microsoft VC++ 团队的电子邮件更新 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.

关于c# - 值结构未在 WinRT 中初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37212642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com