我必须将每个单词的最后一个字母大写。
输入:这是堆栈溢出
输出:这是堆栈流
我试图用下面的代码实现它:
return String.Join(" ", s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Last((s1 => Char.ToUpper(s1)))));
但它无法编译。
我在语句 Char.ToUpper(s1)
上有两个错误
错误 1:
Cannot implicitly convert type 'char' to 'bool'
错误 2:
Cannot convert lambda expression to delegate type 'System.Func' because some of the return types in the block are not implicitly convertible to the delegate return type
最佳答案
这个呢?
var result = String.Join(" ", s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(c => c.Substring(0, c.Length - 1) + char.ToUpper(c.Last())));
它获取单词的整个子字符串并仅更改最后一个字符。
关于c# - 无法将 lambda 表达式转换为委托(delegate)类型 'System.Func<char,bool>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25999156/