char 的增量

1

本文介绍了char 的增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我发现了一些问题,询问如何让 char 'B' 返回 'C' 然后 'D' 等.答案非常复杂,而且大多只是矫枉过正.

I found some question asking how to let char 'B' to return 'C' and then 'D' etc. The answers were quite complex and mostly just overkill.

为什么不简单地使用这个:

Why not to use simply this:

char X='A';
X++

从 A 到 Z,接下来呢?

It goes from A to Z and what next?

推荐答案

如果您对给出的结果感到满意,那很好.

If you're happy with the results that gives, then that's fine.

通常当我看到这样的问题时,他们希望从Z"换行到AA"或类似的东西——比如 Excel 列.显然只是增加一个 char 不会这样做 - 它会转到 '['.

Usually when I've seen questions like that, they want to wrap from "Z" to "AA" or something like that that though - like Excel columns. Clearly just incrementing a char won't do that - it would go to '['.

或者,即使在单个字符内,有效值的范围也可能是不连续的——最明显的例子是十六进制.如果你增加 '9' 你会得到 ':' 而不是你可能想要的 'a' 或 'A'.所需的顺序很少是Unicode 给你什么".

Alternatively, even within a single character, the range of valid values may be non-contiguous - the obvious example being hex. If you increment '9' you get ':' instead of the 'a' or 'A' which you probably wanted. The desired order is rarely "whatever Unicode gives you".

这篇关于char 的增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14