C#中for循環的變種有以下幾種:
foreach (var item in collection)
{
// do something
}
for (int i = collection.Length - 1; i >= 0; i--)
{
// do something
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
// do something
}
}
foreach (var (item, index) in collection.WithIndex())
{
// do something
}
while (condition)
{
// do something
}
do
{
// do something
} while (condition);