title: Calling a method when initializing object
body: <p>I'm looking at a way of cleaning up some code. I have the below</p>
  
  <pre><code>  var sprite1 = new Sprite(_content.Load&lt;Texture2D&gt;("Content/Block.png"));
    sprite1.Position = new Vector2f(100, 100);
    sprite1.SetInput(Key.A, Key.D, Key.W, Key.S);
  
    var sprite2 = new Sprite(_content.Load&lt;Texture2D&gt;("Content/Block.png"));
    sprite2.Position = new Vector2f(200, 100);
    sprite2.SetInput(Key.Left, Key.Right, Key.Up, Key.Down);
  
    _sprites = new List&lt;Sprite&gt;()
    {
      sprite1,
      sprite2,
    };
  </code></pre>
  
  <p>I'd like to initialize the "Sprite" when adding it to the list. But the problem I'm having is the "SetInput" method. That method is optional.</p>
  
  <p>I know this isn't syntactically correct, but below is the sort of thing I'm talking about</p>
  
  <pre><code>  _sprites = new List&lt;Sprite&gt;()
    {
      new Sprite(_content.Load&lt;Texture2D&gt;("Content/Block.png")) { Position = new Vector2f(100, 100), SetInput(Key.A, Key.D, Key.W, Key.S) },
    };
  </code></pre>
  
  <p>As you can see I'm attempting to call a method in a similar to way you can set properties.</p>
  
  <p>Here are the ways I'm thinking of getting around it</p>
  
  <ol>
  <li><p>Optional parameters constructor for the keys</p>
  
  <pre><code>public Sprite(Texture2D texture, Key? left, Key? right, Key? up, Key? down)
  </code></pre></li>
  <li><p>A second constructor with the keys</p>
  
  <pre><code>public Sprite(Texture2D texture, Key left, Key right, Key up Key down)
  </code></pre></li>
  <li><p>Creating a delegate in the "Sprite" class that is assigned when initialized, and then loop around all the _sprites, calling the method</p></li>
  </ol>
  
  <p>The code I've put at the start is fine, I'm just wondering if there is a 'better' way?</p>
  
  <p>Thanks.</p>