【发布时间】:2019-11-30 04:06:37
【问题描述】:
我想创建一个翻转字符串顺序的函数
例如:"hi" => "ih"
这是我目前得到的代码:
public static string Flip(this string Str)
{
char[] chararray = Str.ToCharArray();
string output = "";
chararray. //i dont know what methoud should be used to execute action
return output;
}
问题是,我想知道在 lambda 表达式中当前选择的对象的索引是什么,例如:x in (x => x ) indexOf 不是一个选项,因为可以有多个字符来自同一类型
我怎么知道索引?
编辑: 我不想知道如何反转字符串,我想知道如何在 lambda 表达式中找到对象的索引
【问题讨论】:
-
@fubo 阅读编辑
-
我只是想说有比
indexOf更好的方法来翻转字符串 -
你可以使用this重载的
Select方法。所以你可以写chararray.Select((ch, index) => ... -
根据 linq 方法,您可以输入格式为
Func<TSource,Int32,Boolean>的谓词,其中Int32是索引。例如:test.Where((x, i) => i % 2 == 0)
标签: c# arrays linq indexing lambda