[英]How would I skip spaces in a foreach loop?
C#newbie here。
我使用foreach語句循環遍歷一串字符,並根據它們在字母表中的位置將數值寫入int 。
這工作正常但是當我嘗試跳過字符串中的空格時會拋出此錯誤:
無法分配給“c”,因為它是foreach迭代變量。
這是我的代碼:
foreach (char c in encodedText)
{
if (c = " ");
{
continue;
}
int index = char.ToUpper(c) - 64;
Console.WriteLine(index);
}
試試if (c == ' ')
"
意思是string
。 '
意思是char
。 =
表示分配。 ==
表示平等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.