6

With my code I get messages which shows messages as:

Object initialization can be simplified.

They are not shown as errors? How does simplification help? How do I simplify this code

        _passwordEntry = new Entry();
        _passwordEntry.Keyboard = Keyboard.Text;
        _passwordEntry.Placeholder = "Password";
        stackLayout.Children.Add(_passwordEntry);
user
  • 1,681
  • 5
  • 18
  • 42
  • 1
    These messages are not errors. For the advantages of direct object initialization vs your current code read this: https://stackoverflow.com/questions/12842371/is-there-any-benefit-of-using-an-object-initializer – Steve Sep 01 '19 at 12:57

1 Answers1

12

Place your mouse over the green highlighted code in Visual Studio and press ctrl+; or right click -> quick actions and refactoring.

Visual Studio will certainly offer you the possibility to change your code to this :

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

This is not an error, but an eventual simplification in code

Cid
  • 14,968
  • 4
  • 30
  • 45