【问题标题】:Object Initialization can be simplified :IDE0017可以简化对象初始化:IDE0017
【发布时间】:2020-01-04 20:26:29
【问题描述】:

使用我的代码,我收到的消息显示为:

Object initialization can be simplified.

它们没有显示为错误?简化有什么帮助?如何简化此代码

        _passwordEntry = new Entry();
        _passwordEntry.Keyboard = Keyboard.Text;
        _passwordEntry.Placeholder = "Password";
        stackLayout.Children.Add(_passwordEntry);

【问题讨论】:

标签: c# .net


【解决方案1】:

将鼠标放在 Visual Studio 中绿色突出显示的代码上,然后按 ctrl+; 或右键单击 -> 快速操作和重构。

Visual Studio 肯定会为您提供将代码更改为此的可能性:

stackLayout.Children.Add(new Entry
{
    Keyboard = Keyboard.Text,
    Placeholder = "Password"
});

这不是错误,而是代码的最终简化

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    相关资源
    最近更新 更多