简体   繁体   English

相当于C ++ std :: vector :: at的C#

[英]C# equivalent of the C++ std::vector::at

I've been searching and searching, but fail to find the comparison. 我一直在搜索,但是找不到比较。 Is there a direct conversion, or are more groundwork required to make this work for C#? 是否需要直接转换,还是需要更多基础知识才能使此工作在C#中进行?

What is the C# equivalent of the C++ std::vector::at? C ++ std :: vector :: at的C#等效项是什么?

You can use generic type List for your purposes. 您可以将通用类型List用于您的目的。 Indexer method of this type throws exception in the case of invalid index (in other words, operator[] of list is analogue of vector::at) 这种类型的索引器方法在索引无效的情况下会引发异常(换句话说,列表的operator []与vector :: at类似)

MyList.ElementAt(..) / MyEnumerable.ElementAt(..) do bounds checking, as well as the plain MyList[..] MyList.ElementAt(..) / MyEnumerable.ElementAt(..)进行边界检查,以及普通的MyList[..]
See C# Source Code 参见C#源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM