开发者

Params vs. List<T>, When should I use params keyword and when to use List<t>

I am developing a card game.

In this card game the player can set down few cards in the same turn.

I have a function called SetCardsDown(....)

The card collection parameter can imple开发者_如何学Pythonmented by params keyword or List type.

In which implemenation should I use?

thanks


I'd probably use IEnumerable<T>. That's the most flexible and least restrictive. Once you move to C# 4 (and you should) that will allow callers to use LINQ.

EDIT: Or you can use LINQ with 3.5. But unless you are forced to use something else, move to .NET 4.


params as it will give you the ability to pass in an array. It doesn't seem like you would want to pass in a list because that would give you extra functionality on the parameter that doesn't make sense. Like Add for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜