How to Automatically Add Item to a List As I'm Creating It?

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-04-24T09:07:20Z Indexed on 2010/04/24 9:13 UTC
Read the original article Hit count: 263

Filed under:
|

I want to pass a List into a method, but I only want it to contain 1 item.

Is it possible for me to do this similar to

MyType myType = new MyType();
MyMethod(new List<MyType>{ myType }); // somehow add myType to the list as I'm creating it

© Stack Overflow or respective owner

Related posts about c#

Related posts about list