加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在C#中编写C std :: reverse等价物的最接近的方法是什么?

发布时间:2020-12-15 20:58:45 所属栏目:百科 来源:网络整理
导读:C标准库中的反向算法相当于 template class BidirectionalIterator void reverse (BidirectionalIterator first,BidirectionalIterator last){ while ((first!=last)(first!=--last)) { std::iter_swap (first,last); ++first; }} 根据http://www.cplusplus.
C标准库中的反向算法相当于

template <class BidirectionalIterator>
  void reverse (BidirectionalIterator first,BidirectionalIterator last)
{
  while ((first!=last)&&(first!=--last)) {
    std::iter_swap (first,last);
    ++first;
  }
}

根据http://www.cplusplus.com/reference/algorithm/reverse/.我想在C#中写出等价物:

public void Reverse<T> ( T first,T last ) 
{
    // ... 
}

首先,如何传递两个对IEnumerators的引用,第二个是可以向后传播的引用?有没有一种自然的方法可以做到这一点,还是需要先扩展IEnumerable< T>?

其次,如果上一个问题的答案是否定的,那么是否有一个Skeet认证的C#反向写入方式在通用性和效率方面等于C语言?如果是这样,它是什么?

解决方法

列表< T> interface提供了一个Reverse()方法,它与C equivapent一样.

看看https://msdn.microsoft.com/en-us/library/b0axc2h2(v=vs.110).aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读