备注字段中的最后一个字符

| 我正在通过备注字段循环显示字符,但是我不知道如何停止循环。是否存在像EOF字符这样的字段结束值?有没有更好的方法来确定备注字段的结尾?     
已邀请:
如果您使用
foreach
,则无需担心...
        string memo = \"test\";
        foreach (var x in memo.ToCharArray())
        {
            // you code here
        }
    
我不确定您使用“备注字段”的含义。您是指字符串吗?如果是这样,则可以访问
Length
属性:
string memo = \"hello, world\";
for (int i = 0; i < memo.Length; ++i)
{
    char c = memo[i];
    // do what you want with the character.
}
或者,您可以使用前面建议的use0ѭ:
foreach (var c in memo)
{
    // do what you want with the character
}
    

要回复问题请先登录注册