Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference between continue and break statements in C#?

Câu trả lời

Here is the difference between the continue and break statements in C#:

continue Statement

  • The continue statement is used to skip the current iteration of a loop and move on to the next iteration.
  • When the continue statement is encountered inside a loop, the code block following it is skipped, and the loop moves on to the next iteration.
  • The continue statement is useful when you want to skip certain iterations based on a specific condition, without terminating the entire loop.
  • Example:
csharp Copy
for (int i = 1; i <= 10; i++)
{
    if (i % 2 == 0)
    {
        continue; // Skips even numbers
    }
    Console.WriteLine(i); // Prints only odd numbers
}

break Statement

  • The break statement is used to terminate a loop prematurely, regardless of whether the loop condit...
entry

entry

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between dynamic type variables and object type variables?

middle

What is the use of the IDisposable interface?

senior

What is the difference between Func<string,string> and delegate ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào