开发者

Elements of a C# List [closed]

It开发者_Python百科9;s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

I am using List.ElementAt(0) and List.ElementAt(1) to get the elements I need. How ever I don't want to hardcode 0 and 1 is there any other way in C#


List.First() will work. However, you really shouldn't be using ElementAt if you can help it -- it's slow. And since you're using a list you can indeed help it. Use the indexer instead (List[0], List[1]).


Use a variable?

List.ElementAt(i);


Yes, use a variable instead of hardcoding it. Also if it is a list you could directly use the indexer property: list[0]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜